Watch bubble, insertion, selection, merge, quick and heap sort run step by step, with comparison counts and a full text trace.
Bubble sort — 34 steps
20 comparisons, 11 moves on this input. Complexity below is theoretical, not a measurement.
Every step is reachable with the arrows, the slider or the keyboard — autoplay is optional.
Starting array.
Nobody ships this. It survives because the swap-adjacent-pairs idea is easy to see, and because the early-exit version detects an already-sorted array in one pass.
These bounds are theoretical and describe how work grows, not how fast this runs. The counts above are what happened to this input and are not a benchmark.
Sorting Algorithm Visualizer runs entirely on your device — the sort happens in the page and nothing is uploaded.
You’re on the Free plan. Compare plans
The algorithms run in a pure engine that has no idea a screen exists, and record what they did as a list of steps. This page only draws those steps. That split is what lets the algorithms be checked by assertion — final order against the language's own sort over hundreds of generated inputs, step counts against the known bounds for each algorithm — rather than by watching the bars and hoping.
Two things most visualisers quietly fudge are shown properly. Insertion sort lifts an element out and shifts others into the gap, so the array really does hold a duplicate mid-shift; drawn without saying so that looks like a bug, so the lifted value is shown in hand and the stale slot dimmed. And merge sort is not in place: until a slot is written it still holds its pre-merge value, which is the extra memory merge sort needs and is marked as such.
Settled is kept separate from merely ordered. Selection, bubble and heap sort place elements in their final position; insertion sort's left region is ordered among itself and every element in it can still be pushed right. Colouring both the same makes the animation contradict itself a step later, so they are different colours with different labels.
Bubble sort keeps its early exit, which is the only reason anyone defends it: a pass with no swaps proves the array is sorted and makes the best case linear. Quicksort uses the textbook last-element pivot, so sorted input really does hit its quadratic worst case — showing an algorithm without its bad case misrepresents it.
Complexity is labelled theoretical, because it is. The comparison and move counts are what happened to your input and are not a benchmark: an O(n log n) algorithm can lose to an O(n²) one on sixteen elements, which is why real library sorts switch to insertion sort for small runs.
Because that is what is really in memory. Insertion sort lifts one element out and shifts the others right, so the slot it came from still holds a stale copy until the value is put down. The lifted value is shown in hand and the stale slot is dimmed, rather than the duplicate being hidden.
They mean different things. Solid green is a final position that will not change again; pale green is ordered relative to its neighbours but still able to move. Insertion sort's left-hand region is the second kind, and treating it as settled would make the animation contradict itself.
No. The counts are exactly what happened to the numbers you entered, and the bounds in the complexity panel are theoretical. Which algorithm is fastest in practice depends on constant factors, cache behaviour and input size, none of which Big O describes.
The full trace is listed as text below, one line per step, and clicking any line jumps to it. If your system asks for reduced motion, playback never starts on its own and the transitions are switched off.
Because it uses the textbook last-element pivot, whose worst case is an already-sorted array — and sorted input is extremely common in practice. Production implementations randomise the pivot or fall back to heapsort for exactly this reason.