algo·visual

Merge Sort

Sorting
avgO(n log n)worstO(n log n)spaceO(n)
main
46
47
31
41
50
89
87
37
47
78
22
37
63
37
14
92
aux

Allocate an auxiliary buffer of 16 slots

1 / 145
Size16
Distribution
Custom values2 to 150 whole numbers, each 1 to 999

seed 21

How it works

Bottom-up merge sort: runs of width 1, 2, 4, … are merged pairwise into an auxiliary buffer and copied back, doubling the sorted run length each pass. It is always O(n log n) and stable, but it needs O(n) extra space.

Complexity

Best
O(n log n)
Average
O(n log n)
Worst
O(n log n)
Space
O(n)
Stable
Yes
In place
No

Search algorithms

Jump to any algorithm or page