Pancake sorting explained

Pancake sorting is the mathematical problem of sorting a disordered stack of pancakes in order of size when a spatula can be inserted at any point in the stack and used to flip all pancakes above it. A pancake number is the minimum number of flips required for a given number of pancakes. In this form, the problem was first discussed by American geometer Jacob E. Goodman.[1] A variant of the problem is concerned with burnt pancakes, where each pancake has a burnt side and all pancakes must, in addition, end up with the burnt side on bottom.

All sorting methods require pairs of elements to be compared. For the traditional sorting problem, the usual problem studied is to minimize the number of comparisons required to sort a list. The number of actual operations, such as swapping two elements, is then irrelevant. For pancake sorting problems, in contrast, the aim is to minimize the number of operations, where the only allowed operations are reversals of the elements of some prefix of the sequence. Now, the number of comparisons is irrelevant.

The pancake problems

The original pancake problem

The minimum number of flips required to sort any stack of pancakes has been shown to lie between and (approximately 1.07n and 1.64n), but the exact value is not known.[2]

The simplest pancake sorting algorithm performs at most flips. In this algorithm, a kind of selection sort, we bring the largest pancake not yet sorted to the top with one flip; take it down to its final position with one more flip; and repeat this process for the remaining pancakes.

In 1979, Bill Gates and Christos Papadimitriou gave a lower bound of (approximately 1.06n) flips and an upper bound of . The upper bound was improved, thirty years later, to by a team of researchers at the University of Texas at Dallas, led by Founders Professor Hal Sudborough.[3] [4]

In 2011, Laurent Bulteau, Guillaume Fertin, and Irena Rusu[5] proved that the problem of finding the shortest sequence of flips for a given stack of pancakes is NP-hard, thereby answering a question that had been open for over three decades.

The burnt pancake problem

In a variation called the burnt pancake problem, the bottom of each pancake in the pile is burnt, and the sort must be completed with the burnt side of every pancake down. It is a signed permutation, and if a pancake i is "burnt side up" a negative element i` is put in place of i in the permutation. In 2008, a group of undergraduates built a bacterial computer that can solve a simple example of the burnt pancake problem by programming E. coli to flip segments of DNA which are analogous to burnt pancakes. DNA has an orientation (5' and 3') and an order (promoter before coding). Even though the processing power expressed by DNA flips is low, the high number of bacteria in a culture provides a large parallel computing platform. The bacteria report when they have solved the problem by becoming antibiotic resistant.[6]

The pancake problem on strings

The discussion above presumes that each pancake is unique, that is, the sequence on which the prefix reversals are performed is a permutation. However, "strings" are sequences in which a symbol can repeat, and this repetition may reduce the number of prefix reversals required to sort. Chitturi and Sudborough (2010) and Hurkens et al. (2007) independently showed that the complexity of transforming a compatible string into another with the minimum number of prefix reversals is NP-complete. They also gave bounds for the same. Hurkens et al. gave an exact algorithm to sort binary and ternary strings. Chitturi[7] (2011) proved that the complexity of transforming a compatible signed string into another with the minimum number of signed prefix reversals—the burnt pancake problem on strings—is NP-complete.

History

The pancake sorting problem was first posed by Jacob E. Goodman, writing under the pseudonym "Harry Dweighter" ("harried waiter").

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.[8] [9]

The problem is notable as the topic of the only well-known mathematics paper by Microsoft founder Bill Gates (as William Gates), entitled "Bounds for Sorting by Prefix Reversal" and co-authored with Christos Papadimitriou. Published in 1979, it describes an efficient algorithm for pancake sorting.[10] In addition, the most notable paper published by Futurama co-creator David X. Cohen (as David S. Cohen), co-authored with Manuel Blum, concerned the burnt pancake problem.[11]

The connected problems of signed sorting by reversals and sorting by reversals were also studied more recently. Whereas efficient exact algorithms have been found for the signed sorting by reversals,[12] the problem of sorting by reversals has been proven to be hard even to approximate to within certain constant factor,[13] and also proven to be approximable in polynomial time to within the approximation factor 1.375.[14]

Pancake graphs

See main article: Pancake graph. An n-pancake graph is a graph whose vertices are the permutations of n symbols from 1 to n and its edges are given between permutations transitive by prefix reversals. It is a regular graph with n! vertices, its degree is n-1. The pancake sorting problem and the problem to obtain the diameter of the pancake graph are equivalent.[15]

The pancake graph of dimension n, Pn can be constructed recursively from n copies of Pn-1, by assigning a different element from the set as a suffix to each copy.

Their girth:

g(Pn)=6,ifn>2

.

The γ(Pn) genus of Pn is:[16]

n!\left(

n-4
6

\right)+1\le\gamma(Pn)\len!\left(

n-3\right)-
4
n
2

+1

Since pancake graphs have many interesting properties such as symmetric and recursive structures, small degrees and diameters compared against the size of the graph, much attention is paid to them as a model of interconnection networks for parallel computers.[17] [18] [19] When we regard the pancake graphs as the model of the interconnection networks, the diameter of the graph is a measure that represents the delay of communication.[20] [21]

The pancake graphs are Cayley graphs (thus are vertex-transitive) and are especially attractive for parallel processing. They have sublogarithmic degree and diameter, and are relatively sparse (compared to e.g. hypercubes).[16]

Algorithm

An example of the pancake sorting algorithm is given below in Python. The code is similar to bubble sort or selection sort. def flip(arr, k: int) -> None: left = 0 while left < k: arr[left], arr[k] = arr[k], arr[left] k -= 1 left += 1

def max_index(arr, k: int) -> int: index = 0 for i in range(k): if arr[i] > arr[index]: index = i return index

def pancake_sort(arr) -> None: n = len(arr) while n > 1: maxdex = max_index(arr, n) if maxdex != n - 1: if maxdex != 0: flip(arr, maxdex) flip(arr, n - 1) n -= 1

arreglo = [15, 8, 9, 1, 78, 30, 69, 4, 10]pancake_sort(arreglo)print(arreglo)

Related integer sequences

Height
!! colspan=16
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
11
21 1
31 2 2 1
41 3 6 11 3
51 4 12 35 48 20
61 5 20 79 199 281 133 2
71 6 30 149 543 1357 1903 1016 35
81 7 42 251 1191 4281 10561 15011 8520 455
91 8 56 391 2278 10666 38015 93585 132697 79379 5804
101 9 72 575 3963 22825 106461 377863 919365 1309756 814678 73232
111 10 90 809 6429 43891 252737 1174766 4126515 9981073 14250471 9123648 956354 6
121 11 110 1099 9883 77937 533397 3064788 14141929 49337252 118420043 169332213 111050066 13032704 167
131 12 132 1451 14556 130096 1030505 7046318 40309555 184992275 639783475 1525125357 2183056566 1458653648 186874852 2001

Sequences from The Online Encyclopedia of Integer Sequences:

Further reading

External links

Notes and References

  1. News: Simon . Singh . Simon Singh . Flipping pancakes with mathematics. The Guardian. November 14, 2013. March 25, 2014.
  2. Book: Fertin. G.. Labarre. A.. Rusu. I.. Tannier. E.. Vialette. S. . Combinatorics of Genome Rearrangements. The MIT Press. 2009. 9780262062824.
  3. Web site: Team Bests Young Bill Gates With Improved Answer to So-Called Pancake Problem in Mathematics. University of Texas at Dallas News Center. September 17, 2008. November 10, 2008. A team of UT Dallas computer science students and their faculty adviser have improved upon a longstanding solution to a mathematical conundrum known as the pancake problem. The previous best solution, which stood for almost 30 years, was devised by Bill Gates and one of his Harvard instructors, Christos Papadimitriou, several years before Microsoft was established.. https://web.archive.org/web/20120214070902/http://www.utdallas.edu/news/2008/09/17-002.php?WT.mc_id=NewsEmails&WT.mc_ev=EmailOpen. February 14, 2012. dead.
  4. Chitturi. B.. Fahle. W.. Meng. Z.. Morales. L.. Shields. C. O.. Sudborough. I. H.. Voit. W.. 2009-08-31. An (18/11)n upper bound for sorting by prefix reversals. Theoretical Computer Science. Graphs, Games and Computation: Dedicated to Professor Burkhard Monien on the Occasion of his 65th Birthday. 410. 36. 3372–3390. 10.1016/j.tcs.2008.04.045. free.
  5. Journal of Computer and System Sciences. 10.1016/j.jcss.2015.02.003. Pancake Flipping Is Hard. Bulteau. Laurent. Fertin. Guillaume. Rusu. Irena. 81. 8. 1556–1574. 1111.0434. 2015.
  6. 10.1186/1754-1611-2-8. Engineering bacteria to solve the Burnt Pancake Problem. 2008. Haynes. Karmella A. Broderick. Marian L. Brown. Adam D. Butner. Trevor L. Dickson. James O. Harden. W Lance. Heard. Lane H. Jessen. Eric L. Malloy. Kelly J. Journal of Biological Engineering. 2. 8. 18492232. 2427008. Ogden. Brad J. Rosemond. Sabriya. Simpson. Samantha. Zwack. Erin. Campbell. A Malcolm. Eckdahl. Todd T. Heyer. Laurie J. Laurie Heyer . Poet. Jeffrey L . free .
  7. Discrete Mathematics, Algorithms and Applications. 03. 3. 269–286. 10.1142/S1793830911001206. 2011. Chitturi. Bhadrachalam. A Note on Complexity of Genetic Mutations .
  8. Gargano . L. . Vaccaro . U. . Vozella . A. . 10.1016/0020-0190(93)90043-9 . 6 . Information Processing Letters . 1216942 . 315–320 . Fault tolerant routing in the star and pancake interconnection networks . 45 . 1993. 10.1.1.35.9056 . .
  9. Book: Kaneko . K. . Peng . S. . Disjoint paths routing in pancake graphs . 10.1109/PDCAT.2006.56 . 254–259 . Proceedings of Seventh International Conference on Parallel and Distributed Computing, Applications and Technologies, 2006 (PDCAT '06) . 2006. 978-0-7695-2736-9 . 18777751 . .
  10. Bounds for Sorting by Prefix Reversal . . 27 . 47–57 . 1979 . 10.1016/0012-365X(79)90068-2 . Gates . W. . Papadimitriou . C. . Bill Gates . Christos Papadimitriou . free .
  11. Cohen. D.S. . Blum. M.. 10.1016/0166-218X(94)00009-3. On the problem of sorting burnt pancakes. 1995. Discrete Applied Mathematics. 61. 2. 105. David X. Cohen. Manuel Blum. free.
  12. Kaplan. H.. Shamir. R.. Robert Tarjan. Tarjan. R.E.. Faster and Simpler Algorithm for Sorting Signed Permutations by Reversals. Proc. 8th ACM-SIAM SODA. 1997. 178–87.
  13. Berman. P.. Marek Karpinski. Karpinski. M.. On Some Tighter Inapproximability Results.. Proc. 26th ICALP (1999) . Lecture Notes in Computer Science . 1644. 1999. 200–09.
  14. Berman. P.. Marek Karpinski. Karpinski. M.. Hannenhalli. S.. 1.375-Approximation Algorithms for Sorting by Reversals.. Proc. 10th ESA (2002) . Lecture Notes in Computer Science . 2461. 200–10. 2002.
  15. Asai . Shogo . Kounoike . Yuusuke . Shinano . Yuji . Kaneko . Keiichi . Nagel . Wolfgang E. . Walter . Wolfgang V. . Lehner . Wolfgang . Computing the diameter of 17-pancake graph using a PC cluster . 10.1007/11823285_117 . 1114–1124 . Springer . Lecture Notes in Computer Science . Euro-Par 2006, Parallel Processing, 12th International Euro-Par Conference, Dresden, Germany, August 28 – September 1, 2006, Proceedings . 4128 . 2006. 978-3-540-37783-2 .
  16. Nguyen. Quan. Bettayeb. Said. 2009-11-05. On the Genus of Pancake Network.. The International Arab Journal of Information Technology . 8. 3. 289–292.
  17. Akl. S.G.. Qiu. K.. Stojmenović. I.. 1993. Fundamental algorithms for the star and pancake interconnection networks with applications to computational geometry.. Networks. 23. 4. 215–225. 10.1002/net.3230230403. 10.1.1.363.4949.
  18. Bass. D.W.. Sudborough. I.H.. March 2003. Pancake problems with restricted prefix reversals and some corresponding Cayley networks.. Journal of Parallel and Distributed Computing . 63. 3. 327–336. 10.1016/S0743-7315(03)00033-9. 10.1.1.27.7009.
  19. Berthomé. P.. Ferreira. A.. Perennes. S.. December 1996. Optimal information dissemination in star and pancake networks.. IEEE Transactions on Parallel and Distributed Systems. 7. 12. 1292–1300. 10.1109/71.553290. 10.1.1.44.6681.
  20. Book: Kumar. V.. Grama. A.. Gupta. A.. Karypis. G.. Introduction to Parallel Computing: Design and Analysis of Algorithms. Benjamin/Cummings. 1994.
  21. Book: Quinn, M.J.. Parallel Computing: Theory and Practice. second. McGraw-Hill. 1994.