← Back to Gallery

Cocktail Shaker

Comparisons:0
Swaps:0
Array Accesses:0
Pass:0
Direction:--
Status:Ready

Cocktail Shaker Sort

A bidirectional variant of bubble sort. Alternates between forward passes (bubbling large values right) and backward passes (bubbling small values left). Sorted regions grow from both ends.

Worst:   O(n²)
Average: O(n²)
Best:    O(n)
Space:   O(1)

Advantage over bubble sort: handles "turtles" (small values near the end) much faster.