Shell Sort vs Heap Sort

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

Head-to-head on identical inputs (comparisons)

InputShell SortHeap Sort
Random order2936
Nearly sorted2341
Reversed2735

Complexity

Shell SortHeap Sort
Average timeGap-dependentO(n log n)
Worst timeO(n²)O(n log n)
SpaceO(1)O(1)
StableNoNo

When to use Shell Sort

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

When to use Heap Sort

When you need guaranteed O(n log n) with O(1) extra memory — e.g. embedded or real-time systems.