Sort Target
Algorithm
Speed
Normal ~12s · 135 ms/step
Cocktail shaker sort(1956)
▶ Try this Source
O(n²) ✓ Stable ✓ In-place
🔧 How it works

Alternates between a left-to-right pass that carries the largest unsorted value to the right end, and a right-to-left pass that carries the smallest unsorted value to the left end.

🎯 Key property

A bidirectional extension of Bubble sort that shrinks the unsorted region from both sides each round, neutralising the "turtle" problem where small values near the end of the array slow the forward-only variant.

👁 Watch for
  • Compare direction reverses each pass, left-to-right on the forward pass, right-to-left on the backward pass
  • Swap on the forward pass fires when left > right (pushes larger values rightward); on the backward pass fires when left > right in reverse (pushes smaller values leftward)
  • End of round both the right and left boundaries close in by one, shrinking the unsorted region from both ends simultaneously
Initial State
This is the array before sorting. Follow Cocktail shaker sort step by step.
Main Array
5
0
3
1
8
2
1
3
9
4
2
5
7
6
4
7
0 / 89 ops ( 0.0%) 0.0%
Sorting is
a spectacle.
Algorithms at work, in a daily vertical feed. Watch, play, challenge — and go deeper when you're ready.
Loading 0%
An unhandled error has occurred. Reload 🗙