Selection Sort vs Comb Sort
Across our 3 test inputs, Comb Sort needed 132 comparisons in total versus 135 for Selection Sort. On average Selection Sort runs in O(n²) time and Comb Sort in O(n² / 2ᵖ).
Head-to-head on identical inputs (comparisons)
| Input | Selection Sort | Comb Sort |
|---|---|---|
| Random order | 45 | 50 |
| Nearly sorted | 45 | 41 |
| Reversed | 45 | 41 |
Complexity
| Selection Sort | Comb Sort | |
|---|---|---|
| Average time | O(n²) | O(n² / 2ᵖ) |
| Worst time | O(n²) | O(n²) |
| Space | O(1) | O(1) |
| Stable | No | No |
When to use Selection Sort
When memory writes are expensive (minimizes swaps). Otherwise, insertion sort is generally preferred.
When to use Comb Sort
A simple, low-memory improvement over Bubble Sort for small-to-medium arrays.