Live data from Hacker News

Quadsort: a stable non-recursive merge sort

github.com

11–20 of 110 posts

Re: Quadsort: a stable non-recursive merge sort

#11
post #8

Interesting, but I'm surprised if this is the first time we have sorting algorithm that is swapping more than two elements at a time. I would have guessed every possible iteration of sorting algorithms has been already explored, proven and tested.

> I would have guessed every possible iteration of sorting algorithms has been already explored, proven and tested

The search space is infinite, so exhaustively exploring it is impossible.

Re: Quadsort: a stable non-recursive merge sort

#12

I've never seen a sorting algorithm that uses a non-binary comparison function to order values. Is that a novel technique? It seems really obvious in hindsight, so I'm sure there's just prior art I don't know about.

This is still binary comparison. There are, in general, a number of different sorting algorithms which are optimized for a specific number of elements. In this case, four. It uses five binary comparisons to sort four elements. You can find other algorithms like this, such as an algorithm that uses seven comparisons to sort five items, or one that uses ten comparisons to sort six items.

Ah, I completely misunderstood what was going on with the quad swap at the start. Rereading it makes more sense. Thanks!

Re: Quadsort: a stable non-recursive merge sort

#13
post #8

Interesting, but I'm surprised if this is the first time we have sorting algorithm that is swapping more than two elements at a time. I would have guessed every possible iteration of sorting algorithms has been already explored, proven and tested.

> I would have guessed every possible iteration of sorting algorithms has been already explored, proven and tested The search space is infinite, so exhaustively exploring it is impossible.

Nit: it's possible that there is a finite number of Pareto optimal sorting algorithms, and it may be possible to enumerate those.

Re: Quadsort: a stable non-recursive merge sort

#17
post #8

Interesting, but I'm surprised if this is the first time we have sorting algorithm that is swapping more than two elements at a time. I would have guessed every possible iteration of sorting algorithms has been already explored, proven and tested.

It's a sorting network, invented in the 1950s.

Re: Quadsort: a stable non-recursive merge sort

#18
How does this fare against Python's famous Timsort (used by several languages and systems)? How about the dual-pivot quicksort used by Java for primitive arrays?

Someone has to have put together a nice benchmark for comparing many sorting algorithms. I wish that the author had done some benchmarking first, so that the proposed algorithm can properly be positioned w.r.t. state-of-the-art techniques.

Re: Quadsort: a stable non-recursive merge sort

#19
post #8

Interesting, but I'm surprised if this is the first time we have sorting algorithm that is swapping more than two elements at a time. I would have guessed every possible iteration of sorting algorithms has been already explored, proven and tested.

It isn't. Sorting networks (https://en.wikipedia.org/wiki/Sorting_network) provide the best possible in-place sorting combinations for N elements, where N is currently At lazy glance, it looks kind of like Quadsort has re-derived a variation of the 4-element sorting network.

Re: Quadsort: a stable non-recursive merge sort

#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 clear, but it seems similar to the above construction with a fixed N and then a merge sort afterwards.

Post reply on HN