Pancake Sorting Input: Stack of pancakes, each of different sizes Output: Arrange in order of size (smallest on top) Action: Slip a flipper under one of the pancakes and flip over the whole stack above the flipper 3 2 finish 4 1 1 start 2 3 4
A Flip Action: Slip a flipper under one of the pancakes and flip over the whole stack above the flipper 3 2 4 flip here 1 4 2 3 1
How? 1 2 3 4 2 2 4 3 1 1 4 3 3 1 1 3 2 2 4 4 5 6 Done! 2 1 1 2 3 3 4 4
For n pancakes, at most 2(n-1) flips More Pancakes? 2 4 5 1 6 3 For n pancakes, at most 2(n-1) flips