Watch bubble, selection, insertion, merge, quick and heap sort run one comparison at a time, with step controls and live comparison and write counts.
Bubble sort and selection sort make exactly the same 45 comparisons on the array this tool opens with. One of them writes to the array 52 times; the other writes 16. That gap is invisible in a complexity table, where both are O(n²) and the conversation stops, and it is the reason Sorting Algorithm Visualizer counts comparisons and writes separately and keeps both on screen while the bars move.
Six algorithms share one input box. Type your own numbers, press Randomise, or load a sample, then play the run at up to 30 steps per second, walk it a step at a time in either direction, or drag the scrubber to any moment in the trace. A line under the bars says what the algorithm is doing and why, in the terms the algorithm itself uses.
That is the array on screen when the page loads, and it separates the six cleanly. Bubble finishes in 45 comparisons and 52 writes across 47 steps. Selection matches it comparison for comparison at 45, then writes only 16 times, because it looks for the whole pass’s minimum before it moves anything. Merge does the fewest comparisons at 24, quick needs 26, and heap sits at 40 comparisons and 52 writes. Switching algorithm keeps your array, so those five numbers are a fair test on identical input rather than five separate runs you have to trust.
1 2 3 4 5 6 and watch the pivot settle one position at a time.Between 4 and 50 numbers, and fewer than four returns “Give it at least 4 numbers to sort.” The ceiling is there because every frame is recorded before playback starts, which is what makes stepping backwards and scrubbing possible at all; the trace stops at 8,000 frames, and the worst case in range, bubble sort on 50 descending values, uses 1,225 comparisons and about 1,227 frames, so nothing you can type will actually reach it. Two smaller details: value labels under the bars are dropped above 22 elements, where they stop being legible, and the shortest bar is drawn at 6% of the height rather than 0, so a zero in your array is still visible. Pressing Load Sample moves off the opening array to a set of 32-bit constants, 1000000007 998244353 1000000009 2147483647 4294967295, which is a quick check that the bar scaling is relative rather than absolute.
Algorithm
Starting array.
Step 1 of 47 · 0 comparisons · 0 writes
Best
O(n)
Average
O(n²)
Worst
O(n²)
Space
O(1)
Stable
Yes