Medium Sorting

Merge Sort

Receives an array of integers and returns a new array sorted in ascending order. It uses divide-and-conquer: it splits the array in half, recursively sorts each half, then merges the two sorted halves by comparing their front elements one at a time — always picking the smaller one — and appending any remainder. Guarantees O(n log n) time in all cases. Returns a new array; the original is not modified.

Visualization

Input

Algorithm code

Custom input

Saved inputs

References