SortLab

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

  1. Sweep left-to-right and move the maximum to the end.
  2. Move the right boundary inward.
  3. Sweep right-to-left and move the minimum to the start.
  4. 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.

Compare related strategies