Sorting Algorithms
Watch order emerge one operation at a time. Compare four approaches on the same shuffled numbers.
5–80 numbers to keep the bars readable.
1–100 operations per second. Adjustable while running.
Reset and algorithm changes restore the same numbers. Changing the count or shuffling starts a new set. Use Single step to explore without playback.
Ready
Comparisons: 0 · Array writes: 0
Elapsed animation time: 0.00 s
Actual playback time, including animation delays at the chosen speed. Pauses and manual steps add no time. Speed changes affect the remaining playback, not time already elapsed. This is not a CPU benchmark.
Thick top edge: comparison · ⇄: swap · Dashed outline: partition · P: pivot · Horizontal stripes: sorted prefix (may move) · Diagonal stripes: shifting or final positions · K: held insertion value · ↓: insertion position
Current values
1, 10, 15, 7, 22, 29, 5, 21, 8, 23, 17, 25, 12, 24, 30, 11, 18, 26, 2, 27, 14, 9, 16, 13, 19, 6, 28, 4, 3, 20
Bubble Sort
Compare neighboring numbers and swap them when out of order. Each pass moves the largest remaining number to the end; stop early if no swaps are needed.
These values describe the standard algorithm; the event generator and visualizer use additional memory.
| Algorithm | Best case | Average case | Worst case | Working memory | Stable | In place |
|---|---|---|---|---|---|---|
| Bubble Sort | O(n) | O(n²) | O(n²) | O(1) | Yes | Yes |
| Insertion Sort | O(n) | O(n²) | O(n²) | O(1) | Yes | Yes |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) | Yes | No |
| Quick Sort | O(n log n) | O(n log n) | O(n²) | O(log n) average · O(n) worst | No | Yes |
n is the number of values. Big O describes how work grows as n increases; animation speed does not change it. Bubble Sort can stop in O(n), and Insertion Sort takes O(n) on nearly sorted input. Merge Sort stays O(n log n); this Quick Sort uses the last value as pivot, so ordered inputs can reach O(n²). Space describes the standard algorithm, excluding visualization state.