Algorithm Lab
Visualize sorting algorithms step by step. Runs entirely in your browser.
Comparisons: 0Swaps: 0
Merge Sort
BestO(n log n)
AverageO(n log n)
WorstO(n log n)
SpaceO(n)
StableYes
Legend
Unsorted
Comparing
Swapping
Sorted
How It Works
Merge Sort divides the array in half recursively, sorts each half, then merges them back together. Each level does O(n) work across log n levels, giving O(n log n) guaranteed. Requires O(n) extra space.
Tip: Merge Sort is stable and always O(n log n), making it ideal for sorting linked lists and databases.
Comparison
| Algorithm | Avg | Space |
|---|---|---|
| Bubble Sort | O(n²) | O(1) |
| Insertion Sort | O(n²) | O(1) |
| Merge Sort | O(n log n) | O(n) |
| Merge (Bottom-Up) | O(n log n) | O(n) |
| Quick Sort | O(n log n) | O(log n) |
| Quick (3-Way) | O(n log n) | O(log n) |
| Heap Sort | O(n log n) | O(1) |