PowerPoint PresentationSlide 2Slide 3Slide 4Weekly HomeworkSlide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14How do we sort this stack? How many flips do we need?Slide 16Developing A Notation: Turning pancakes into numbersSlide 18Slide 194 Flips Are SufficientBest Way to SortCan we do better?Four Flips Are NecessarySlide 24Slide 255th Pancake NumberSlide 27What 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 PancakesSlide 37For a particular stack bring-to-top not always optimal? Pn 2n-3Breaking Apart Argumentn PnSlide 42n Pn 2n – 3 for n > 3From ANY stack to sorted stack in ≤ PnSlide 45ANY Stack S to ANY stack T in ≤ PnThe Known Pancake NumbersP18 is UnknownIs This Really Computer Science?Slide 50(17/16)n Pn (5n+5)/3(15/14)n Pn (5n+5)/3(15/14)n Pn (18/11)n(3/2)n BPn 2n-2Slide 55Slide 56Network For n = 3Network For n=4Slide 59Slide 60Mutation DistanceOne “Simple” ProblemHigh Level PointSlide 64Slide 6515-251Great Theoretical Ideas in Computer Science15-251Great Theoretical Ideas in Computer Sciencewww.cs.cmu.edu/~15251Course StafInstructorsVictor AdamchikDanny SleatorTAsDrew Besse Adam Blank Dmtriy Chernyak Sameer Chopra Dan Kilgallin Alan PierceHomework50%Final20%In-Class Quizzes4%3 Tests30%Lowest non-programming HW grade is droppedLowest quiz droppedAll tests countedGradingWeekly HomeworkTen points per day late penaltyNo homework will be accepted more than two days lateHomeworks handed out Tuesdays (except for a couple) and are due the following Tuesday, at midnightHomework MUST be typeset, and a single PDF fileCollaboration + CheatingYou may NOT share written workYou may NOT use Google (or other search engines)You MUST sign the class honor codeYou may NOT use solutions to previous years’ homework.TextbookThere is NO textbook for this classWe have class notes in wiki formatYou too can edit the wiki!!!((( )))Feel free to ask questionsAnd take advantage of our generous office hours15-251Cooking for Computer ScientistsLecture 1 (January 12, 2010)Pancakes With A Problem!He does this by grabbing several from the top and flipping them over, repeating this (varying the number he flips) as many times as necessaryThe chefs at our place are sloppy: when they prepare pancakes, they come out all diferent sizesWhen the waiter delivers them to a customer, he rearranges them (so that smallest is on top, and so on, down to the largest at the bottom)How do we sort this stack?How many flips do we need?How do we sort this stack?How many flips do we need?Developing A Notation:Turning pancakes into numbers5234152341How do we sort this stack?How many flips do we need?52341523414 Flips Are Sufficient1234552341432152341514325Best Way to Sort52341 X = Smallest number of flips required to sort:? X ?Upper BoundLower Bound4Can we do better?52341Four Flips Are Necessary523414132514325Flip 2 must bring 4 to top (if it didn’t, we would take more than three flips)Flip 1 has to put 5 on bottom (else wewould take 3 flips just to get 5 to bottom)If we could do it in three flips:Upper BoundLower Bound4 X 4X = 452341 where X = Smallest number of flips required to sort:MAX over s stacks of 5 of MIN # of flips to sort sP5 = . . . . . .120111932X1X2X3X119X12052341412345543215th Pancake NumberNumber of flips required to sort the worst case stack of 5 pancakesP5 =5th Pancake Number? P5 ?Upper BoundLower Bound4“For all 5-pancake stacks s, we can sort s in this much time”“There exists a 5-pancake stack which will make metake this much time”MAX over s stacks of n pancakes of MIN # of flips to sort sPn =The number of flips required to sort the worst-case stack of n pancakesPn =What is Pn for small n?Can you do n = 0, 1, 2, 3 ?Initial Values of Pnn 30 1 2Pn0 0 1 3P3 = 3132requires 3 Flips, henceANY stack of 3 can be done by getting the big one to the bottom (≤ 2 flips), and then using ≤ 1 flips to handle the top twoP3 ≥ 3nth Pancake NumberNumber of flips required to sort the worst case stack of n pancakesPn =? Pn ?Upper BoundLower BoundBracketing: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 ?Try to find upper and lower bounds on Pn,for n > 3Bring biggest to top Place it on bottom Bring next largest to topPlace second from bottomAnd so on…Bring-to-top MethodUpper Bound On Pn:Bring-to-top Method For n PancakesIf n=1, no work required — we are done!Otherwise, flip pancake n to top and then flip it to position nNow use: Bring To Top Method For n-1 PancakesTotal Cost: at most 2(n-1) = 2n –2 flipsBetter Upper Bound On Pn:Bring-to-top Method For n PancakesIf n=2, at most one flip and we are done!Otherwise, flip pancake n to top and then flip it to position nNow use: Bring To Top Method For n-1 PancakesTotal Cost: at most 2(n-2) + 1 = 2n – 3 flips? Pn 2n-3For a particular stackbring-to-top not always optimalBring-to-top takes 5 flips, but we can do in 4 flips3214552341231454132514325? Pn 2n-3What other bounds can you prove on Pn?916Breaking Apart ArgumentSuppose a stack S has a pair of adjacent pancakes that will not be adjacent in the sorted stackAny sequence of flips that sorts stack S must have one flip that inserts the spatula between that pair and breaks them apartFurthermore, this is true of the “pair” formed by the bottom pancake of S and the platen Pn2468..n135..n-1SS contains n pairs that will S contains n pairs that will need to be broken apart during need to be broken apart during any sequence that sorts itany sequence that sorts itSuppose n is even21Detail: This construction only works when n>2n Pn1357..n246..n-1SS contains n pairs that will S contains n pairs that will need to be broken apart during need to be broken apart during any sequence that sorts itany sequence that sorts itSuppose n is odd132Detail: This construction only works when n>3n Pn 2n – 3 for n > 3Bring-to-top is within a factor of 2 of optimal!From ANY stack to sorted stack in ≤ PnReverse the sequences we use to sortFrom sorted stack to ANY stack in ≤ Pn ? ((( )))Hence, from ANY stack to ANY stack in ≤ 2PnCan you find a
View Full Document