TECHNOLOGY · 5 MIN
How computers sort a million things fast
Split, sort the halves, merge: the trick that turns hours into seconds.
With a clever method like merge sort, doubling the number of items makes sorting take...
Comparing every pair of a million items takes 500 billion steps; merge sort needs about 20 million.
Split and merge
Merge sort splits the list in half, then splits those halves, until every piece holds one item, and one item is already sorted. Then it merges the pieces back together. Merging two sorted lists is quick: keep taking the smaller of their two front items.
Why it’s so much faster
Comparing every item with every other takes about n² ÷ 2 steps: half a trillion for a million items. Merge sort needs only about n × log₂n. A million items can be halved about 20 times, and each level touches every item once: about 20 million steps.
Turn on JavaScript to watch each board draw itself, solve one on your own and explain it back.
More in Technology
See the whole library