Merge Sort
Interactive lab
Try it: Merge Sort
How merge sort splits the list in halves down to single items, then merges sorted halves back together through a buffer.
How it works
- Split the range in half until each piece has one value.
- Merge two sorted halves by repeatedly taking the smaller front value into a buffer.
- On ties take the left value first, so the sort is stable.
- Copy the buffer back; about n·log₂n comparisons in every case.
Default run (33 steps): Merge sort, ascending: [8, 3, 5, 1, 9, 2]. … Sorted ascending: [1, 2, 3, 5, 8, 9] — 11 comparisons, 16 writes.
Simplified: Up to 12 numbers from 0 to 99. The comparison table runs all five algorithms on the same input. Python's own sort() uses Timsort.
Educational simulation
Loading the simulation…