Illustration of QuickSort and MergeSort as two sides of the same coin:
http://lkozma.net/images/sort/duality.pdf I find this somehow both obvious and counter-intuitive, and usually the two algorithms are not presented in this way, as duals of each other. I wrote up this view in more detail, but the figure above should be self-explanatory:
http://lkozma.net/blog/a-dual-view-of-sorting-algorithms/
There's an important distinction that your explanation glosses over, which is that MergeSort is an out-of-place sort while QuickSort is in-place. As a practical matter, this distinction is important and it makes the two algorithms not quite duals. Your explanation of why we can assume that QuickSort pivots are medians makes sense, but it also glosses over one of the deep insights about why QuickSort works at all, which is that with unsorted data, the choice of pivot will rarely be bad (it will be "near the middle on average.")
Yes, this efficiency-aspect is not captured in the illustration -- while splitting perfectly _by index_ comes for free, splitting perfectly _by value_ needs nontrivial work (median-finding).
Yes and with naïve median-finding comes pathological inputs that hit the worst case O(n^2). Something to watch out for if you’re sorting user-provided input as that could open you up to some silly denial of service attacks!
Comments (312) 127 threads
Earlier commentshttps://jpmens.net/2021/04/09/the-unix-magic-poster/
How did you hook your c64 up to an LCD?
Continue this thread — 2 replies
Also see: https://news.ycombinator.com/item?id=27029196
https://en.wikipedia.org/wiki/Fourier_series#/media/File:Fou...
The main resource on learning Erlang, https://learnyousomeerlang.com, has a lot of funny ones, some of which are useful.
https://www.toptal.com/developers/sorting-algorithms
Illustration of QuickSort and MergeSort as two sides of the same coin: http://lkozma.net/images/sort/duality.pdf
I find this somehow both obvious and counter-intuitive, and usually the two algorithms are not presented in this way, as duals of each other.
I wrote up this view in more detail, but the figure above should be self-explanatory: http://lkozma.net/blog/a-dual-view-of-sorting-algorithms/
All comments shown.
Couldn't load more comments. Check your connection and try again.