Live data from Hacker News

Quadsort: a stable non-recursive merge sort

github.com

81–90 of 110 posts

Re: Quadsort: a stable non-recursive merge sort

#81
post #72
post #70

Earlier quoted context omitted.

I think it's different in that you don't care what the output of a hash is, as long as it's sufficiently unique or whatever. Whereas here the buckets are are intimately tied to the input. It's more of an arithmetic hack I'd say, as it only works on decimal numbers

Radix sort works in any base

Sorry, I meant decimal as in excluding some rationals e.g. not 1/3.

Re: Quadsort: a stable non-recursive merge sort

#82
post #74
post #71

Earlier quoted context omitted.

No one is claiming that this sort algorithm (or any other) is asymptotically faster than O(n log(n)). It can be mathematically proved that no sort algorithm can improve on this. The object with sort algorithms is to find one with good constant-factor performance on typical inputs. Frankly, I am more persuaded by the arguments in favor of an algorithm like "Tim-sort", which doesn't claim to micro-optimize hardware mor…

I'm quite a noob, and this is a bit off-topic, but if it's mathematically proven that no sorting algorithm can be faster then O(n*log(n)), but we know for sure that checking if an array is sorted is O(n), then doesn't that prove that P ≠ NP?

[deleted]

Re: Quadsort: a stable non-recursive merge sort

#83

C's qsort() is notoriously bad because the comparison function isn't inlined, meaning the majority of time is spent in call overhead. Zhangxp1998 ported quadsort to C++ and compared with std::sort and found it to be slower: https://gist.github.com/zhangxp1998/0e2fa30656c894017d183e0d... Shameless self promotion, if you want a faster sorting implementation, check out pdqsort ( https://github.com/orlp/pdqsort ) which i…

Comparing a stable sort to a normal sort is unfair. Compare it with std::stable_sort.

Too late to edit but I read the article again and they compares it favorably to qsort so it makes sense to point out it's worse than std sort.

Re: Quadsort: a stable non-recursive merge sort

#84
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.

Sort your data. Store it somewhere and then later add more unsorted data.

Re: Quadsort: a stable non-recursive merge sort

#85
post #80
post #72

Earlier quoted context omitted.

Radix sort works in any base

Radix sort also works on strings, etc. (anything that can be lexicographically ordered)

I guess it could work well for sets of strings that you know will not go above a certain length? But after that it might become painful, i.e. the algorithm complexity will start depending on the maximum string length

Re: Quadsort: a stable non-recursive merge sort

#86
post #59

Earlier quoted context omitted.

"Mostly-sorted" is a very vague definition.

Usually what people mean by mostly sorted in CS is that there is some small K such that each element in the input is no more than K places from the position it would be in if the input was sorted.

According to this definition, the "random tail" test data is not "mostly sorted".

Re: Quadsort: a stable non-recursive merge sort

#87

qsort has to invoke your comparison function repeatedly, which incurs a lot of overhead. Try C++'s std::sort

This feels a little unfair; the function is invoked the same number of times, but C++ has a mechanism for removing the overhead of calling a function (inlining).

I looked at disassembly of generated binary, sure, function calls inside quad sort were also inlined.

Re: Quadsort: a stable non-recursive merge sort

#88

C's qsort() is notoriously bad because the comparison function isn't inlined, meaning the majority of time is spent in call overhead. Zhangxp1998 ported quadsort to C++ and compared with std::sort and found it to be slower: https://gist.github.com/zhangxp1998/0e2fa30656c894017d183e0d... Shameless self promotion, if you want a faster sorting implementation, check out pdqsort ( https://github.com/orlp/pdqsort ) which i…

Comparing a stable sort to a normal sort is unfair. Compare it with std::stable_sort.

I agree is unfair. The point of my benchmark was that the OP's claim "quad sort is faster than quicksort" is false.

Re: Quadsort: a stable non-recursive merge sort

#89
post #86

Earlier quoted context omitted.

Usually what people mean by mostly sorted in CS is that there is some small K such that each element in the input is no more than K places from the position it would be in if the input was sorted.

According to this definition, the "random tail" test data is not "mostly sorted".

Well you could extend the definition to allow a small number of items which are entirely out of place. The point is that the right sort algorithm depends a lot on tthe distribution of input data and how much you care about worst-case vs average case trade offs.
Post reply on HN