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