Build intuition for how and why different sorts work, and how their cost grows with input size.
Simple comparison sorts — easy to follow, but O(n²) once the input grows.
Watch bubble sort compare neighbouring values and swap them, one step at a time, until the largest bubble to the end.
Scan the unsorted part for the smallest value and move it to the front — a growing sorted region, one selection at a time.
Build a sorted list one item at a time — each new value sinks left into its place, like sorting cards in your hand.
Insertion sort with a head start: swap elements a large gap apart, then shrink the gap so values leap most of the way home. In-place; speed depends on the gap sequence.
Comparison sorts that reach the O(n log n) speed limit.
Divide and conquer: split the array into halves down to single elements, then merge the sorted pieces back together — reliably O(n log n).
Divide and conquer by partitioning: pick a pivot, put smaller values left and larger right, then sort each side. Fast in practice — average O(n log n), in-place.
Build a max-heap inside the array, then repeatedly extract the largest to the back — reliably O(n log n) and in-place.
Real-world defaults that combine several strategies to be fast and safe everywhere.
Sort by the values themselves — beating the comparison limit on the right kind of data.
A non-comparison sort: drop each value into a bin for its value, then read the bins in order. O(n + k) when the value range k is small.
Sort multi-digit numbers without comparisons: bucket by one digit at a time, least significant first, using a stable counting pass each round. O(d·(n + k)).
Scatter values into range buckets, sort each bucket, then gather in order. O(n) average when the data is spread evenly; O(n²) worst case.
How the sorts stack up against each other — cost by input size, and stability.
Two sorts, one set of axes. Slide the input size n and watch O(n²) pull away from O(n log n) — the same comparison made concrete, with live counts.
A sort is “stable” when items with equal keys keep their original order. See the difference on a tie, and why it matters for sorting by more than one key.