Guided Notes

Faster Sorting: Quick, Merge, Counting & Radix

Divide-and-conquer sorts that run in O(n log n), and non-comparison sorts that can beat it.

Divide and conquer

Slide 1 / 5

The fast general-purpose sorts use divide and conquer:

1. Divide the problem into smaller pieces. 2. Conquer each piece (often recursively). 3. Combine the results.

Splitting in half repeatedly gives about log n levels, and each level does O(n) work — so the total is O(n log n). For a million items that's roughly 20 million steps instead of a trillion for O(n²).