Selection Sort vs Cocktail Shaker Sort

Across our 3 test inputs, Cocktail Shaker Sort needed 101 comparisons in total versus 135 for Selection Sort. Cocktail Shaker Sort is stable; Selection Sort is not.

Head-to-head on identical inputs (comparisons)

InputSelection SortCocktail Shaker Sort
Random order4539
Nearly sorted4517
Reversed4545

Complexity

Selection SortCocktail Shaker Sort
Average timeO(n²)O(n²)
Worst timeO(n²)O(n²)
SpaceO(1)O(1)
StableNoYes

When to use Selection Sort

When memory writes are expensive (minimizes swaps). Otherwise, insertion sort is generally preferred.

When to use Cocktail Shaker Sort

Teaching, or small arrays where small values sit near the end (where plain Bubble Sort is slow).