Comb Sort vs Shell Sort

Across our 3 test inputs, Shell Sort needed 79 comparisons in total versus 132 for Comb Sort. On average Comb Sort runs in O(n² / 2ᵖ) time and Shell Sort in Gap-dependent.

Head-to-head on identical inputs (comparisons)

InputComb SortShell Sort
Random order5029
Nearly sorted4123
Reversed4127

Complexity

Comb SortShell Sort
Average timeO(n² / 2ᵖ)Gap-dependent
Worst timeO(n²)O(n²)
SpaceO(1)O(1)
StableNoNo

When to use Comb Sort

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

When to use Shell Sort

Medium-sized arrays and embedded systems where recursion or extra memory is undesirable.