Live data from Hacker News

Quadsort: a stable non-recursive merge sort

github.com

21–30 of 110 posts

Re: Quadsort: a stable non-recursive merge sort

#21
post #15
post #4

I’ll read the article when I get the chance, but would this be in-place?

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.

Re: Quadsort: a stable non-recursive merge sort

#22

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

See https://gist.github.com/zhangxp1998/0e2fa30656c894017d183e0d... for a comparison of quadsort with C++'s std::sort. The compare functions are inlined.

Re: Quadsort: a stable non-recursive merge sort

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

You technically do not need any swap space to swap two numbers. So algorithms which only use swaps could be implemented fully in place.

Re: Quadsort: a stable non-recursive merge sort

#24
post #2

Man, that's a good gif

You may enjoy this: https://www.youtube.com/watch?v=kPRA0W1kECg

There are several similar videos on YouTube demonstrating sorts. If that's a bit sterile for you, you can get a more human touch via the playlist https://www.youtube.com/watch?v=EdIKIf9mHk0&list=PLOmdoKois7...

Re: Quadsort: a stable non-recursive merge sort

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

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

Re: Quadsort: a stable non-recursive merge sort

#26
post #13

Earlier quoted context omitted.

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

Oh man if I could efficiently enumerate algorithms across the Pareto front of anything I’d be a happy camper.

Procedures that enumerate Turing machines are generally very easy, or nigh impossible

Re: Quadsort: a stable non-recursive merge sort

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

In place kinda means the opposite of in swap space.

Re: Quadsort: a stable non-recursive merge sort

#28
post #15
post #4

I’ll read the article when I get the chance, but would this be in-place?

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

Swap space is allocated here: https://github.com/scandum/quadsort/blob/c3bcf139c59eb296b28...

Re: Quadsort: a stable non-recursive merge sort

#29
post #24
post #2

Man, that's a good gif

You may enjoy this: https://www.youtube.com/watch?v=kPRA0W1kECg There are several similar videos on YouTube demonstrating sorts. If that's a bit sterile for you, you can get a more human touch via the playlist https://www.youtube.com/watch?v=EdIKIf9mHk0&list=PLOmdoKois7...

This is terrific

Re: Quadsort: a stable non-recursive merge sort

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

> If somebody could find a way to generalize the sorting network algorithm for any number of input elements

In section 2 in that Wikipedia article, it links to many constructions that do exactly that.

A couple are O(n log(n)), but complicated and impractical. The algorithms people use are O(n log^2(n)) ones.

FWIW, sorting networks are data-independent. I.e. for any input, you always compare-and-swap the same elements.

Post reply on HN