Sorting algorithms
Eight algorithms race on their real operation counts. Move the size control and the order the labels promise falls apart.
Eight sorting algorithms race on the same shuffled array and are ranked by the operations they actually took, with the size in the reader's hands. The lanes are stacked in one column so the fronts line up, each holding that algorithm's own array being sorted and a clock that stops on its last operation. Every operation costs a thousandth of a second at every size, so a race takes as long as the work takes rather than being squeezed into a fixed slot: 1.6 seconds at forty elements and 41 at two hundred, which is what n squared looks like on a wall clock. At 40 elements the labels tell the truth. Drop to 16 and radix, merge and heap sort all finish behind selection sort, which is why CPython and libstdc++ hand their short runs to insertion sort instead of recursing. Selection sort and bubble sort make exactly the same 780 comparisons at 40 elements, because both walk every pair and neither stops early, and bubble sort writes 830 times against selection sort's 74.
← All cheatsheets