Playground

Merge Sort

Observe how the array is recursively split in half and then merged back together in sorted order.

Merge Sort

Divide the array in half recursively, then merge sorted halves back together. Watch each subarray come into focus as the algorithm dives deeper.

Time O(n log n)  |  Space O(n)  |  Stable  |  Divide & Conquer
Data
Size8
Speed2000ms
Full Array
38
27
43
3
9
82
10
55
38
27
43
3
9
82
10
55
Press SORT to begin

MERGE SORT

mergeSort(arr, lo, hi):
if lo >= hi: return
mid = (lo + hi) / 2
mergeSort(arr, lo, mid)
mergeSort(arr, mid+1, hi)
merge(lo, mid, hi)
// array is sorted

Console

n = 8
>Press SORT to begin…