Divide & Conquer: Merge Sort
HardAcc. 75.4%
+50 XP 25
Stable Merging
Merge Sort is a stable, recursive algorithm that splits the array in the middle, sorts both halves, and merges them using a two-pointer approach.
The Assignment
Your function receives data.
- Base case: array length <= 1.
- Split array in middle.
- Recursively call mergeSort.
- Merge sorted halves and print result.
01EXAMPLE 1
Input
[38, 27, 43, 3, 9, 82, 10]Output
3 9 10 27 38 43 82Explanation: Sorted using stable merging.
Constraints
- O(n log n) time complexity.
- Consistent O(n log n) performance regardless of input order.
AlgorithmsSortingRecursion
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
data[38,27,43,3,9,82,10]
Expected Output
3 9 10 27 38 43 82
Click RUN to test your solution