Bubble Sort
Swap neighbours that are out of order until each pass floats one value home.
Decision · step 2 of 24Bubble Sort: Seven values
5 is larger than 1, so they swap.
What you will see
COMPARE neighbours -> SWAP if out of order -> the largest settles on the right; sorted region grows from the right.
Cost
| Best | O(n) |
|---|---|
| Average | O(n^2) |
| Worst | O(n^2) |
| Space | O(1) |
Best case O(n) requires the early-exit check on an already sorted array.
Properties
- ✓ comparison based
- ✓ stable
- ✓ in place
- ✓ adaptive
- × online
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, compare two runs.
Screen readers: Cells announce index, value and state (comparing, swapped, sorted); each step announces the comparison outcome and any move.
Reduced motion: Swaps become value crossfades with outline flashes; sorted-region growth is a static span change.
Before this
Related
Variants
- Early Exit Stop when a pass makes no swaps.