Live data from Hacker News

Quadsort: a stable non-recursive merge sort

github.com

51–60 of 110 posts

Re: Quadsort: a stable non-recursive merge sort

#51
post #15

Earlier quoted context omitted.

From the article: "These operations do require doubling the memory overhead for the swap space." It seems it is not in-place.

I'm pretty sure it's in-place, thus the need for "swap space" to hold the values that are being moved.

It looks like it is doubling the "swap space" used in a standard merge sort, not the "swap space" use in a quicksort.

Re: Quadsort: a stable non-recursive merge sort

#53
post #20

This reminds me of a programming exercise I was asked to write when I first learned programming: write a sorting program generator that given N, generates a program that sorts an array of N elements optimally: the generated code has N! branches, one for each possible permutation. With some CSE help from the compiler, it can be really quite fast at the expense of code size. The author's explanation isn't entirely clea…

A truly optimal sorting for a given N is a nontrivial problem. By truly optimal I mean the actual absolute minimum in the number of comparisons, no O(...) approximation.

For five elements the lower bound from counting the permutations is ceil(log2(5!)) which says you cannot sort 5 elements in less than 7 comparisons.

An actual 7 comparison algorithm exists but it is not very easy to write it. For greater numbers it gets much much trickier - in general the log(#permutations) lower bound cannot be met.

Re: Quadsort: a stable non-recursive merge sort

#54
post #52
post #47

This Quicksort is almost twice as fast https://rextester.com/XHCGA23293

Only in the random case. Already sorted in either direction and it's ~10x slower.

Who wants to sort sorted data. If the input data is more often sorted, you can test this before sorting.

Re: Quadsort: a stable non-recursive merge sort

#56
post #54
post #52

Earlier quoted context omitted.

Only in the random case. Already sorted in either direction and it's ~10x slower.

Who wants to sort sorted data. If the input data is more often sorted, you can test this before sorting.

Sorting sorted or mostly-sorted arrays is not uncommon in many use cases.

Re: Quadsort: a stable non-recursive merge sort

#57
post #54
post #52

Earlier quoted context omitted.

Only in the random case. Already sorted in either direction and it's ~10x slower.

Who wants to sort sorted data. If the input data is more often sorted, you can test this before sorting.

Data can be partially sorted and it happens quite often. As I understood, it's exactly the purpose of quadsort - to leverage locally ordered sequences.

Re: Quadsort: a stable non-recursive merge sort

#58
post #53
post #20

This reminds me of a programming exercise I was asked to write when I first learned programming: write a sorting program generator that given N, generates a program that sorts an array of N elements optimally: the generated code has N! branches, one for each possible permutation. With some CSE help from the compiler, it can be really quite fast at the expense of code size. The author's explanation isn't entirely clea…

A truly optimal sorting for a given N is a nontrivial problem. By truly optimal I mean the actual absolute minimum in the number of comparisons, no O(...) approximation. For five elements the lower bound from counting the permutations is ceil(log2(5!)) which says you cannot sort 5 elements in less than 7 comparisons. An actual 7 comparison algorithm exists but it is not very easy to write it. For greater numbers it g…

Agreed. My use of the word "optimal" in the original comment was a bit careless.

Re: Quadsort: a stable non-recursive merge sort

#59
post #56
post #54

Earlier quoted context omitted.

Who wants to sort sorted data. If the input data is more often sorted, you can test this before sorting.

Sorting sorted or mostly-sorted arrays is not uncommon in many use cases.

"Mostly-sorted" is a very vague definition.

Re: Quadsort: a stable non-recursive merge sort

#60

Earlier quoted context omitted.

I'm pretty sure it's in-place, thus the need for "swap space" to hold the values that are being moved.

The term "in-place" almost always means O(1) additional space, whereas this uses O(n) additional space.

technically quick sort needs O(log N) additional space and it is still considered in-place. I guess the threshold for in-place-ness would be less than linear additional space?
Post reply on HN