Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Weekly HomeworkSlide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Developing A Notation: Turning pancakes into numbersHow do we sort this stack? How many flips do we need?4 Flips Are SufficientBest Way to SortFour Flips Are NecessarySlide 20Slide 215th Pancake NumberSlide 23What 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 33Bring-to-top not always optimal for a particular stack? Pn 2n-3Breaking Apart Argumentn PnSlide 38n Pn 2n – 3 for n > 3From ANY stack to sorted stack in ≤ PnSlide 41ANY Stack S to ANY stack T in ≤ PnThe Known Pancake NumbersP14 is UnknownIs This Really Computer Science?Slide 46(17/16)n Pn (5n+5)/3(15/14)n Pn (5n+5)/3Slide 49Slide 50Network For n = 3Network For n=4Slide 53Slide 54Mutation DistanceOne “Simple” ProblemHigh Level PointSlide 58Slide 5915-251Cooking for Computer ScientistsI understand that making pancakes can be a dangerous activity and that, by doing so, I am taking a risk that I may be injured.I hereby assume all the risk described above, even if Luis von Ahn, his TAs or agents, through negligence or otherwise, otherwise be deemed liable. I hereby release, waive, discharge covenant not to sue Luis von Ahn, his TAs or any agents, participants, sponsoring agencies, sponsors, or others associated with the event, and, if applicable, owners of premises used to conduct the pancake cooking event, from any and all liability arising out of my participation, even if the liability arises out of negligence that may not be foreseeable at this time.Please don’t burn yourself…Administrative Crapolawww.cs.cmu.edu/~15251Check this Website OFTEN!Course StafInstructorsLuis von AhnAnupam GuptaTAsYifen HuangDaniel NuferDaniel SchaferHomework40%Final25%In-Class Quizzes5%3 In-Recitation Tests 25%Participation5%If Suzie gets 60,90,80 in her tests, how many total test points will she have in her final grade?(0.05)(60) + (0.10)(90) + (0.10)(80) = 20Lowest homework grade is droppedLowest test grade is worth halfGradingWeekly HomeworkTen points per day late penaltyNo homework will be accepted more than three days lateHomework will go out every Tuesday and is due the Tuesday afterAssignment 1:The Great 251 Hunt!You will work in randomly chosen groups of 4The actual Puzzle Hunt will start at 8pm tonightYou will need at least one digital camera per groupCan buy a digital camera for $8 nowadays!Shared SecretCollaboration + CheatingYou may NOT share written workYou may NOT use Google, or solutions to previous years’ homeworkYou MUST sign the class honor codeTextbookThere is NO textbook for this classWe have class notes in wiki formatYou too can edit the wiki!!!((( )))Feel free to ask questionsLecture 1 (August 28, 2007)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)Developing A Notation:Turning pancakes into numbers5234152341How do we sort this stack?How many flips do we need?523414 Flips Are Sufficient1234552341432152341514325Best Way to Sort52341 X = Smallest number of flips required to sort:? X ?Upper BoundLower Bound4Four Flips Are Necessary523414132514325Flip 2 must bring 4 to top (if it didn’t, we would spend more than 3)Flip 1 has to put 5 on bottomIf we could do it in three flips:Upper BoundLower Bound4 X 4X = 4MAX over s 2 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 Bound4MAX over s 2 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-3Bring-to-top not always optimal for a particular stackBring-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
View Full Document