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)
| Input | Quick Sort | Shell Sort |
|---|---|---|
| Random order | 22 | 29 |
| Nearly sorted | 39 | 23 |
| Reversed | 45 | 27 |
Complexity
| Quick Sort | Shell Sort | |
|---|---|---|
| Average time | O(n log n) | Gap-dependent |
| Worst time | O(n²) | O(n²) |
| Space | O(log n) | O(1) |
| Stable | No | No |
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.