Foundations · Beginner
Cocktail Shaker Sort
Run Bubble Sort in both directions, tightening the unsorted region from both ends.
- Best
- O(n)
- Average
- O(n²)
- Worst
- O(n²)
- Space
- O(1)
- Stability
- Stable
- Memory model
- In-place
How it builds order
- Sweep left-to-right and move the maximum to the end.
- Move the right boundary inward.
- Sweep right-to-left and move the minimum to the start.
- Move the left boundary inward.
Why it works
Each double pass locks at least one value at both ends while preserving the sorted outer regions.
Watch for: A forward pass fixes the maximum; the backward pass fixes the minimum.
The interactive version of this page adds the full trace, synchronized pseudocode, practice decisions, input experiments, and mastery review.