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.

  1. Base case: array length <= 1.
  2. Split array in middle.
  3. Recursively call mergeSort.
  4. Merge sorted halves and print result.

01EXAMPLE 1

Input[38, 27, 43, 3, 9, 82, 10]
Output3 9 10 27 38 43 82

Explanation: Sorted using stable merging.

Constraints

  • O(n log n) time complexity.
  • Consistent O(n log n) performance regardless of input order.
AlgorithmsSortingRecursion
JavaScript
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