Merge Sort is a stable Divide and Conquer algorithm that recursively splits an array into halves until single elements remain, then merges sorted halves back together.
Divide cards into two piles. Sort each pile, then merge them back by comparing the top card of each pile and picking the smaller one.
~4,483 steps (Linearithmic)
O(N log N) Linearithmic Time
O(N) Aux Memory
Memory growth rate as N expands.
Relative efficiency rating for large N.
| Operation | Time Complexity | Space Complexity |
|---|---|---|
| Best / Average / Worst Case | O(N log N) | O(N) |
function mergeSort(arr) {
if (arr.length <= 1) return arr;
const mid = Math.floor(arr.length / 2);
const left = mergeSort(arr.slice(0, mid));
const right = mergeSort(arr.slice(mid));
return merge(left, right);
}Sorts huge datasets that exceed RAM capacity using disk chunks.
Used for object reference arrays requiring stable sorting.
Validate your conceptual understanding, operation mechanics, and core concepts of Merge Sort.
Merge Sort is guaranteed stable, meaning equal elements preserve their original relative order in the output!
Array loaded. Trigger Merge Sort to visualize recursive divide & conquer tree decomposition.