Compare. Swap. Repeat.

Bubble Sort compares adjacent values and swaps those that are out of ascending order. Each complete pass puts one more largest element in its final position.

Average and worst-case time complexity: O(n²).

Visual explanation

01

Compare

Inspect two adjacent numbers.

02

Swap

Exchange them when the left number is larger.

03

Repeat

Continue passes until sorted.