Bubble Sort Visualization
Bubble Sort walks through the list swapping neighbours that are out of order, until a pass makes no swaps.
How it works
Bubble Sort compares each pair of neighbours and swaps them if they are in the wrong order. After one full pass, the largest value has bubbled to the end; after the next, the second largest, and so on. When a pass makes no swaps at all, the list is sorted.
On random data that means about n²/2 comparisons and a similar number of swaps, which is why Bubble Sort is the classic example of a slow algorithm. It is stable, in place, and on a list that is already sorted it finishes in a single pass.
What to watch for
Watch the largest values drift to the end one by one while small values creep the other way a single step per pass.
Complexity
- Best
- n
- Average
- n²
- Worst
- n²
- Extra space
- 1
- Stable
- Yes
Race it
Same shuffle, same speed, one winner: Bubble vs Insertion. Or open the studio to try other layouts, sizes and speeds, and make a video of it.
FAQ
Why is Bubble Sort so slow?
A value can only move one position per comparison toward the front, so a small value near the end needs almost n passes to arrive.
Is Bubble Sort stable?
Yes. It only swaps neighbours that are strictly out of order.
Is Bubble Sort ever used?
Rarely for real work. It is mostly used to teach sorting, and on tiny or already sorted lists it is fine.