Bubble Sort vs Shell Sort

Across our 3 test inputs, Shell Sort needed 79 comparisons in total versus 135 for Bubble Sort. On average Bubble Sort runs in O(n²) time and Shell Sort in Gap-dependent. Bubble Sort is stable; Shell Sort is not.

Head-to-head on identical inputs (comparisons)

InputBubble SortShell Sort
Random order4529
Nearly sorted4523
Reversed4527

Complexity

Bubble SortShell Sort
Average timeO(n²)Gap-dependent
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 Shell Sort

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