5 ms·
I wonder if they tried shell sort? IME it's so close to bubble sort in implementation that you can view it as a trivial optimization.
by megameter 6y ago
I wonder if they tried shell sort? IME it's so close to bubble sort in implementation that you can view it as a trivial optimization.
- kzrdude 6y agoAnd just a few shells could be added, to make this optimization right? If the sequence is 1, 4, 10, 23, .. one could start by just adding a pass with 4 and then 1. https://stackoverflow.com/questions/2539545/fastest-gap-sequence-for-shell-sort https://stackoverflow.com/questions/2539545/fastest-gap-sequ... I don't know how to select the fallback sort loop size (related to cache line size maybe?); in his github code he uses 16 elements as the threshold.
- gerbenst 6y agoA very interesting suggestion indeed. Shell sort is an insertion sort though. It owes its better complexity from being able to breaking out of loop early. But these are difficult to predict branches that bubble sort avoids. Certainly this is worth an experiment
- kzrdude 6y agoWell, you are the expert :). I misremebered and thought of the base case for shell sort to be a kind of bubble sort.