Pancake Sort

Sorting by flipping! The delicious algorithm inspired by breakfast.

Algorithm Steps

  1. Find the largest unsorted pancake.
  2. Flip the stack up to that pancake so it moves to the top.
  3. Flip the entire unsorted prefix so the pancake lands at the bottom.
  4. 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

← Back to gallery