Merge Sort Visualizer

Visualize Merge Sort dividing an array and merging sorted ranges with clear animations, step controls, metrics, and algorithm notes.

Current status: Comparing the highlighted values to decide the next move.

Comma-separated numbers, up to 20 values.

Balanced

Live operation

compare

Step 1 / 20
5
[0]
3
[1]
8
[2]
4
[3]
2
[4]
Compare halvesWrite merged valueFully sorted

Comparisons

1

Moves / writes

0

Confirmed sorted

0 / 5

Algorithm notes

What to watch for

Merge Sort uses divide and conquer: recursively split until ranges are tiny, then compare the front of each half while writing a merged sequence back into the array.

Concept guide

Review the mental model, tradeoffs, and practical use cases after you experiment.

Merge Sort Complete Info Card

Divide & ConquerStable Sort

Merge Sort is a divide-and-conquer algorithm that recursively splits the array into halves, sorts them, and then merges the sorted halves back together.

Algorithm Characteristics

Time Complexity (Best)

Consistent across all cases

O(n log n)

Time Complexity (Average)

Typical case performance

O(n log n)

Time Complexity (Worst)

Guaranteed performance

O(n log n)

Space Complexity

Auxiliary space for merging

O(n)

Stable

Maintains relative order of equal elements

Yes

Parallelizable

Divide step works well for parallel processing

Yes

Sorting Process Steps

1

Divide the unsorted array into n subarrays (each with 1 element)

2

Repeatedly merge subarrays to produce new sorted subarrays

3

Continue until only one sorted array remains

4

Merge operation compares elements from each subarray

5

Copy elements in sorted order during merge

Comparison with Other O(n log n) Sorts

AlgorithmTime ComplexitySpace ComplexityStable
Quick SortO(n log n)O(log n)No
Heap SortO(n log n)O(1)No
Merge SortO(n log n)O(n)Yes

Optimal Use Cases

  • Large datasets requiring stable sort
  • External sorting (disk/tape storage)
  • When data doesn't fit in memory (with modifications)

When to Avoid

  • Memory-constrained environments
  • Small datasets (use Insertion Sort)
  • When in-place sorting is required
Pro Tip: Merge Sort is the algorithm of choice for most standard library sorting implementations when stability is needed.
Guaranteed O(n log n)StableDivide & Conquer