Selection Sort vs Shell Sort

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

Head-to-head on identical inputs (comparisons)

InputSelection SortShell Sort
Random order4529
Nearly sorted4523
Reversed4527

Complexity

Selection SortShell Sort
Average timeO(n²)Gap-dependent
Worst timeO(n²)O(n²)
SpaceO(1)O(1)
StableNoNo

When to use Selection Sort

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

When to use Shell Sort

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