Pancakes With A Problem!Slide 2Slide 3Developing A Notation: Turning pancakes into numbersSlide 5Slide 6Slide 7How do we sort this stack? How many flips do we need?4 Flips Are SufficientAlgebraic RepresentationSlide 114 Flips Are NecessarySlide 13Slide 145th Pancake NumberSlide 16The 5th Pancake Number: The MAX of the X’sP5 = MAX over s 2 stacks of 5 of MIN # of flips to sort sSlide 19Pn = The number of flips required to sort a worst-case stack of n pancakes.What is Pn for small n?Initial Values Of PnP3 = 3nth Pancake NumberBracketing: What are the best lower and upper bounds that I can prove?? Pn ?Bring To Top MethodUpper Bound On Pn: Bring To Top Method For n PancakesBetter Upper Bound On Pn: Bring To Top Method For n PancakesBring to top not always optimal for a particular stack? Pn 2n - 3Breaking Apart ArgumentSlide 33n PnSlide 35Slide 36Slide 37Slide 38n ≤ Pn ≤ 2n – 3 (for n ≥ 3)Slide 40From ANY stack to sorted stack in · Pn.Slide 42From ANY stack to ANY stack in · 2Pn.From ANY Stack S to ANY stack T in · PnThe Known Pancake NumbersP14 Is UnknownIs This Really Computer Science?Slide 48(17/16)n Pn (5n+5)/3(15/14)n Pn (5n+5)/3PermutationSlide 52Ultra-Useful FactRepresenting A PermutationA Permutation is a NOUNSlide 56Permute A Permutation.FORMALLYPancake NetworkNetwork For n=3Network For n=4Pancake Network: Routing DelayPancake Network: ReliabilityMutation DistanceOne “Simple” ProblemStudy BeeHigh Level PointReferencesPancakes With A Problem!Pancakes With A Problem!Great Theoretical Ideas In Computer ScienceGreat Theoretical Ideas In Computer ScienceSteven Steven RudichRudichCS 15-251 Spring CS 15-251 Spring 20052005Lecture 3Lecture 3Jan 18, 2005Jan 18, 2005Carnegie Mellon Carnegie Mellon UniversityUniversityPlease feel free to ask questions! ((( )))The chef at our place is sloppy, and when he prepares a stack of pancakes they come out all different sizes. Therefore, when I deliver them to a customer, on the way to the table I rearrange them (so that the smallest winds up on top, and so on, down to the largest at the bottom).I do this by grabbing several from the top and flipping them over, repeating this (varying the number I flip) as many times as necessary.Developing A Notation:Developing A Notation:Turning pancakes into numbersTurning pancakes into numbersDeveloping A Notation:Developing A Notation:Turning pancakes into numbersTurning pancakes into numbers12345Developing A Notation:Developing A Notation:Turning pancakes into numbersTurning pancakes into numbers23451Developing A Notation:Developing A Notation:Turning pancakes into numbersTurning pancakes into numbers52341How do we sort this stack?How do we sort this stack?How many flips do we need?How many flips do we need?523414 Flips Are Sufficient4 Flips Are Sufficient1234552341432152341514325Algebraic RepresentationAlgebraic Representation52341X = The smallest number of flips required to sort:? X ?Upper BoundLower BoundAlgebraic RepresentationAlgebraic Representation52341X = The smallest number of flips required to sort:? X 4Upper BoundLower Bound4 Flips Are Necessary4 Flips Are Necessary523414132514325Flip 1 has to put 5 on bottomFlip 2 must bring 4 to top.? X 4Lower BoundUpper BoundLower Bound4 X 4X = 455thth Pancake Number Pancake NumberP5 = The number of flips required to sort the worst case stack of 5 pancakes.? P5 ?Upper BoundLower Bound55thth Pancake Number Pancake NumberP5 = The number of flips required to sort the worst case stack of 5 pancakes.4 P5 ?Upper BoundLower BoundThe 5The 5thth Pancake Number: Pancake Number: The MAX of the X’sThe MAX of the X’s120119932. . . . . . . X1X2X3X119X120523414P5 = MAX over s 2 stacks of 5 of MIN # of flips to sort s120119932. . . . . . . X1X2X3X119X120523414Pn MAX over s stacks of n pancakes of MIN # of flips to sort sOr,The number of flips required to sort a worst-case stack of n pancakes.Be Cool.Learn Math-speak.Pn = The number of flips required to sort a worst-case stack of n pancakes.What is Pn for small n?Can you do n = 0, 1, 2, 3 ?Initial Values Of Pnn 0 1 2 3Pn0 0 1 3PP33 = 3 = 311332 requires 3 Flips, hence 2 requires 3 Flips, hence PP33 ¸¸ 3. 3.ANYANY stack of 3 can be done in stack of 3 can be done in 33 flips. flips. Get the big one to the bottom (Get the big one to the bottom (·· 2 flips). 2 flips).Use Use ·· 1 more flip to handle the top two. 1 more flip to handle the top two.Hence, Hence, PP33 ·· 3. 3.nth Pancake NumberPn = Number of flips required to sort a worst case stack of n pancakes.? Pn ?Upper BoundLower BoundBracketing:Bracketing:What are the best lower and upper What are the best lower and upper bounds that I can prove?bounds that I can prove?≤ f(x) ≤[]? Pn ?Take a few minutes to try and prove bounds on Pn,for n>3.Bring To Top Method Bring biggest to top. Place it on bottom. Bring next largest to top. Place second from bottom. And so on…Upper Bound On PUpper Bound On Pnn::Bring To Top Method For n Bring To Top Method For n PancakesPancakesIf n=1, no work - we are done.If n=1, no work - we are done.Else: Else: flip pancake n to topflip pancake n to top and then and then flip it to position nflip it to position n..Now use: Now use: Bring To Top Method Bring To Top Method For n-1 PancakesFor n-1 PancakesTotal Cost: at most 2(n-1) = 2n –2 flips.Better Upper Bound On PBetter Upper Bound On Pnn::Bring To Top Method For n Bring To Top Method For n PancakesPancakesIf n=2, use one flip and we are done.If n=2, use one flip and we are done.Else: flip pancake n to top and then Else: flip pancake n to top and then flip it to position n.flip it to position n.Now use: Now use: Bring To Top Method Bring To Top Method For n-1 PancakesFor n-1 PancakesTotal Cost: at most 2(n-2) + 1 = 2n –3 flips.Bring to top not always optimal Bring to top not always optimal for a particular stackfor a particular stack5 flips, but can be done in 4 flips5 flips, but can be done in 4 flips3214552341231454132514325? Pn 2n - 3What bounds can you prove on Pn?916Breaking Apart ArgumentBreaking Apart ArgumentSuppose a stack S contains a pair Suppose a stack S contains a pair of adjacent pancakes that will not of adjacent pancakes that will not be adjacent in the sorted stack. be adjacent in the sorted stack. Any sequence of flips that sorts Any sequence of flips that sorts stack S
View Full Document