1. The playground
Choose an algorithm, an array size, and a step delay. The bars show the current array; yellow is being compared, red was just swapped, cyan was written by merge sort, purple is the pivot, and green is in its final position. The counters are the operations this input actually required.
2. What to notice
- Bubble and insertion are O(n²); merge and quick are O(n log n) average. On 24 elements the gap is visible; on 40 it is obvious.
- Merge sort writes into a temporary array, so its counter is writes, not swaps. It is stable, but it uses O(n) extra memory.
- Quicksort is in-place but not stable. Its worst case is O(n²), which is easiest to see on already sorted input with a bad pivot rule.
- The bar colors tell the story of one step: compare, swap/write, pivot, final. Pause at any point and read the counters.
3. The algorithms behind it
All four algorithms are comparison sorts. Merge sort splits and merges; quicksort partitions around a pivot. The recurrence and the partition are the two ideas worth keeping.
Merge sort
Quicksort average
The playground generates a fresh trace whenever the array or algorithm changes. The trace is an array of snapshots, so scrubbing backward is free and the counters stay consistent with the picture.