Quick Sort vs Shell Sort

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

Head-to-head on identical inputs (comparisons)

InputQuick SortShell Sort
Random order2229
Nearly sorted3923
Reversed4527

Complexity

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

When to use Quick Sort

General-purpose sorting. Fast in practice due to excellent cache locality. Default algorithm used in many language libraries (often hybridised as Introsort).

When to use Shell Sort

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