Codacoda
Back to Academy

sorting

Merge Sort

Merge Sort is a stable, divide-and-conquer algorithm that divides the array into halves, recursively sorts each half, and then merges the sorted halves back together. It guarantees O(n log n) performance in all cases.

Use Cases

  • When stable sorting is required
  • Sorting linked lists efficiently
  • External sorting (large files that don't fit in memory)

Complexity Analysis

MetricBestAverageWorst
TimeO(n log n)O(n log n)O(n log n)
SpaceO(n)

Visualization

64
34
25
12
22
11
90
Speed:1x
Initial arrayStep 1 / 27

Implementation

Output

Click "Run Code" to see output...