Insertion Sort vs Comb Sort
Across our 3 test inputs, Insertion Sort needed 85 comparisons in total versus 132 for Comb Sort. On average Insertion Sort runs in O(n²) time and Comb Sort in O(n² / 2ᵖ). Insertion Sort is stable; Comb Sort is not.
Head-to-head on identical inputs (comparisons)
| Input | Insertion Sort | Comb Sort |
|---|---|---|
| Random order | 30 | 50 |
| Nearly sorted | 10 | 41 |
| Reversed | 45 | 41 |
Complexity
| Insertion Sort | Comb Sort | |
|---|---|---|
| Average time | O(n²) | O(n² / 2ᵖ) |
| Worst time | O(n²) | O(n²) |
| Space | O(1) | O(1) |
| Stable | Yes | No |
When to use Insertion Sort
Small arrays or nearly-sorted arrays. O(n) best case for already-sorted input. Used as a subroutine in Timsort.
When to use Comb Sort
A simple, low-memory improvement over Bubble Sort for small-to-medium arrays.