DSA · Reimagined
Sorting medium time O(n log n) space O(n)

Merge Sort

Recursively split the array in half until each piece is one element, then merge sorted pieces back together. Each merge fills a separate buffer one value at a time — comparing the fronts of the two halves — then copies the buffer back, so no value is ever lost or duplicated.

array
6
0
2
1
8
2
4
3
3
4
7
5
1
6
5
7
merge buffer
0
1
2
3
4
5
6
7

Merge sort: split down to single elements, then merge through a buffer.

1 / 40

Practice

Machine twin: /dsa-viz-v2/merge-sort.json — the full deterministic run as structured data.