Bubble Sort Explorer
Step-by-step visualization of Bubble Sort, with the live comparison, swaps, and inversions remaining.
This interactive bubble sort visualization shows the simplest sorting algorithm in motion: walk the array comparing each adjacent pair, and whenever the left value is larger, swap them. Big values keep winning their comparisons, so on every pass the largest remaining element "bubbles" to the end and locks into place — turning green and never being touched again.
The animation makes the algorithm's cost tangible. Each swap of neighbours removes exactly one inversion (a pair in the wrong order), so the number of swaps is fixed by the input itself, not by luck. Without the early-exit optimization the comparison count is always $C = \frac{n(n-1)}{2}$, which is why bubble sort is $O(n^2)$. Turn on early exit and a pass with zero swaps proves the array is already sorted, dropping the best case to $O(n)$.
Watch the compared pair highlight, see swaps animate as elements slide past each other, and track the "inversions remaining" curve fall to zero as the array becomes sorted. Step through it comparison by comparison, swap by swap, or a full pass at a time. Try the reversed preset for the worst case where every comparison forces a swap, or a nearly-sorted array with early exit for the best case — a single clean pass. Paste your own numbers to sort any list you like.