Merge Sort Visualizer
Visualize Merge Sort dividing an array and merging sorted ranges with clear animations, step controls, metrics, and algorithm notes.
Comma-separated numbers, up to 20 values.
Live operation
compare
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
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
Time Complexity (Average)
Typical case performance
Time Complexity (Worst)
Guaranteed performance
Space Complexity
Auxiliary space for merging
Stable
Maintains relative order of equal elements
Parallelizable
Divide step works well for parallel processing
Sorting Process Steps
Divide the unsorted array into n subarrays (each with 1 element)
Repeatedly merge subarrays to produce new sorted subarrays
Continue until only one sorted array remains
Merge operation compares elements from each subarray
Copy elements in sorted order during merge
Comparison with Other O(n log n) Sorts
| Algorithm | Time Complexity | Space Complexity | Stable |
|---|---|---|---|
| Quick Sort | O(n log n) | O(log n) | No |
| Heap Sort | O(n log n) | O(1) | No |
| Merge Sort | O(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