Bubble Sort

Repeatedly compares adjacent elements and swaps them if they are in the wrong order.

Stable:YesIn-place:No
Complexity
Best
O(n) (with early-exit)
Average
O(n²)
Worst
O(n²)
Space
O(1)
When to use: Mostly educational; rarely used in production.Very simple to implementSlow on large inputs (O(n²) average/worst-case)
Pseudocode
for i from 0 to n-1
for j from 0 to n-i-2
if arr[j] > arr[j+1]
swap arr[j], arr[j+1]
Waiting to start…