SortingAnimated
Bubble Sort
Swap adjacent out-of-order pairs until none remain.
Time
O(n²)
Extra space
O(1)
Use it for
Teaching; nearly-sorted tiny lists.
How it works
- Compare each pair of neighbours from the left.
- If a pair is out of order, swap it.
- After one full pass the largest value has "bubbled" to the end.
- Repeat on the shorter unsorted part; stop when a pass makes no swaps.
Watch it run
Loading animation…