Algorithm Steps
- Find the largest unsorted pancake.
- Flip the stack up to that pancake so it moves to the top.
- Flip the entire unsorted prefix so the pancake lands at the bottom.
- Reduce the problem size and repeat.
Complexity
Pancake Sort runs in O(n)
flips and O(n^2)
time in the traditional implementation. It is famous for its simplicity and the fun mental model of a spatula flipping a stack.
In the Gallery
- Bars represent pancakes of different diameters.
- Highlighted bars show the section being flipped.
- Press "Shuffle" to serve up another random stack.