Sorting Visualizer
Watch a sort run one step at a time. Press play and follow the bars, the highlighted pseudocode, and the running tally of work done.
Repeatedly swaps adjacent out-of-order pairs. The simplest sort to picture — but O(n²) and slow.
Pseudocode
Bubble SortLegend
Tip: Space play/pause · ← → step
Learn sorting
Sorting arranges items into order (here, smallest → largest). All three sorts on this page are comparison sorts: they decide what goes where purely by comparing pairs of values.
They're also in-place (they reuse the same array, O(1) extra memory) and simple to reason about. The trade-off is speed: each runs in O(n²) on average, so they shine on small or nearly-sorted inputs rather than huge datasets.
Stable
Keeps equal values in their original relative order. Bubble & insertion are stable; selection is not.
In-place
Sorts within the array itself — no second array needed, so memory stays at O(1).