Bubble Sort
Compares adjacent elements and swaps them if out of order, bubbling the largest to the end each pass.
0 elements
>Ready — Bubble Sort
Code
1
2
3
4
5
6
7
Analysis
BEST O(n)
AVG O(n²)
WORST O(n²)
SPACE O(1)
Bubble Sort walks through the array comparing each pair of adjacent elements, swapping them if they’re in the wrong order. After each pass the largest unsorted element “bubbles” to its final position. Passes repeat until no swaps are needed.