Bubble Sort vs Selection Sort

Across our 3 test inputs, both made the same number of comparisons (135). Bubble Sort is stable; Selection Sort is not.

Head-to-head on identical inputs (comparisons)

InputBubble SortSelection Sort
Random order4545
Nearly sorted4545
Reversed4545

Complexity

Bubble SortSelection Sort
Average timeO(n²)O(n²)
Worst timeO(n²)O(n²)
SpaceO(1)O(1)
StableYesNo

When to use Bubble Sort

Educational purposes and very small arrays. Never use in production due to O(n²) worst-case.

When to use Selection Sort

When memory writes are expensive (minimizes swaps). Otherwise, insertion sort is generally preferred.