Quick Sort vs Cocktail Shaker Sort

Across our 3 test inputs, Cocktail Shaker Sort needed 101 comparisons in total versus 106 for Quick Sort. On average Quick Sort runs in O(n log n) time and Cocktail Shaker Sort in O(n²). Cocktail Shaker Sort is stable; Quick Sort is not.

Head-to-head on identical inputs (comparisons)

InputQuick SortCocktail Shaker Sort
Random order2239
Nearly sorted3917
Reversed4545

Complexity

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

When to use Quick Sort

General-purpose sorting. Fast in practice due to excellent cache locality. Default algorithm used in many language libraries (often hybridised as Introsort).

When to use Cocktail Shaker Sort

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