Cocktail Shaker Sort vs Comb Sort
Across our 3 test inputs, Cocktail Shaker Sort needed 101 comparisons in total versus 132 for Comb Sort. On average Cocktail Shaker Sort runs in O(n²) time and Comb Sort in O(n² / 2ᵖ). Cocktail Shaker Sort is stable; Comb Sort is not.
Head-to-head on identical inputs (comparisons)
| Input | Cocktail Shaker Sort | Comb Sort |
|---|---|---|
| Random order | 39 | 50 |
| Nearly sorted | 17 | 41 |
| Reversed | 45 | 41 |
Complexity
| Cocktail Shaker 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 Cocktail Shaker Sort
Teaching, or small arrays where small values sit near the end (where plain Bubble Sort is slow).
When to use Comb Sort
A simple, low-memory improvement over Bubble Sort for small-to-medium arrays.