| |||||||||
Pancake sorting is a variation of the sorting problem in which the only allowed operation is to reverse the elements of some prefix of the sequence. The goal is to sort the sequence in as few reversals as possible.
The name can be understood by thinking of a stack of pancakes in which one is allowed to take the top k pancakes and flip them.
Whereas in the regular sorting problem one usually seeks to minimize the number of comparisons, in pancake sorting the operation is different. Furthermore, this operation cannot be performed in constant time on a Von Neumann machine. Because of this, pancake sorting can be accomplished in linear time, which is not possible for comparison sorting. The constant is known to lie between 1 and 5/3, but the exact value is not known.
The simplest pancake sorting algorithm requires at most 2n-3 flips. In this algorithm, a variation of selection sort, we bring the largest pancake not yet sorted to the top with one flip, and then take it down to its final position with one more, then repeat this for the remaining pancakes.
In a more difficult variation called the Burnt Pancake Problem, the bottom of each pancake in the pile is burnt, and we must complete the sort with the burnt side of every pancake down.
Although seen more often as an educational device, pancake sorting also appears in applications in parallel processor networks, in which it can provide an effective routing algorithm between processors.
As an interesting piece of trivia, the only well-known paper ever published by Microsoft Chairman and billionaire Bill Gates, entitled "Bounds for Sorting by Prefix Reversal," describes an efficient algorithm for pancake sorting.
The following describes the number of flips per specified stack height. the first number is the height of the pancake stack. The following numbers are the number of stacks of that height that require 0, 1, 2, . . . flips to get back to the starting stack.
Sequences from :