0 day streak

Sorting means putting items in order, and it’s one of the most studied problems in computing because so much else depends on it: searching, deduplication, merging and grouping all get easier on sorted data. Algorithms that work only by comparing pairs of items need about n log n comparisons in the worst case, and the classic ones (merge sort, quicksort, heapsort) reach that bound. In practice, the winners also exploit real data and hardware: Timsort, used by Python and Java, spots stretches that are already in order, and quicksort is fast because it works in place with cache-friendly memory access. Stability, keeping equal items in their original order, matters when you sort by one field after another.

In this lesson: A race arena: algorithms run side by side on random, sorted, reversed or few-unique data, with comparison and swap counters. Duplicate keys are colored to show stability. Timsort shows run detection and galloping.