Bubble Sort vs Comb Sort

Across our 3 test inputs, Comb Sort needed 132 comparisons in total versus 135 for Bubble Sort. On average Bubble Sort runs in O(n²) time and Comb Sort in O(n² / 2ᵖ). Bubble Sort is stable; Comb Sort is not.

Head-to-head on identical inputs (comparisons)

InputBubble SortComb Sort
Random order4550
Nearly sorted4541
Reversed4541

Complexity

Bubble SortComb Sort
Average timeO(n²)O(n² / 2ᵖ)
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 Comb Sort

A simple, low-memory improvement over Bubble Sort for small-to-medium arrays.