What is Merge Sort?
Split the list in halves, sort each half, then merge them back in order.
Type a tool name, format or task
Split the list in halves, sort each half, then merge them back in order. Interactive step-by-step animation with JavaScript code, complexity and front-end use cases.
Loading animation...
Split the list in halves, sort each half, then merge them back in order. Split the list into two halves until each part has one value. Merge two sorted halves by always taking the smaller front value. Keep merging until one sorted list remains. Time complexity: O(n log n). Space complexity: O(n). Stable and predictable, so it is behind Array.prototype.sort in several engines. Stability keeps equal table rows in their original order.
Split the list in halves, sort each half, then merge them back in order.
Time: O(n log n). Space: O(n).
Stable and predictable, so it is behind Array.prototype.sort in several engines. Stability keeps equal table rows in their original order.
No. This converter runs in your browser for ordinary use, so the input is not sent to a backend by this tool.
Keep working without searching again.
Merge sort splits the list in half again and again, then merges the sorted halves back together.
function mergeSort(arr) {if (arr.length < 2) return arr;const mid = arr.length >> 1;const left = mergeSort(arr.slice(0, mid));const right = mergeSort(arr.slice(mid));const out = [];while (left.length && right.length) {out.push(left[0] <= right[0] ? left.shift() : right.shift());}return [...out, ...left, ...right];}
Tip: use the arrow keys to step and the space bar to play or pause.