1 / 70

15-251

15-251. Great Theoretical Ideas in Computer Science. 15-251. Great Theoretical Ideas in Computer Science. www.cs.cmu.edu/~15251. Course Staff. Instructors. TAs. Adam Blank Dmitriy Chernyak Tim Wilson. Anupam Gupta Danny Sleator. Final 30%. Homework 30%. In-Class Quizzes 5%.

fancy
Download Presentation

15-251

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 15-251 Great Theoretical Ideas in Computer Science

  2. 15-251 Great Theoretical Ideas in Computer Science www.cs.cmu.edu/~15251

  3. Course Staff Instructors TAs Adam Blank Dmitriy Chernyak Tim Wilson Anupam Gupta Danny Sleator

  4. Final 30% Homework 30% In-Class Quizzes 5% 3 In-Recitation Tests 35% Grading Lowest homework grade is dropped Lowest test grade is worth half If Suzie gets 60,100,70 in her tests, how many total test points will she have in her final grade? (0.07)(60) + (0.14)(100) + (0.14)(70) = 28

  5. 9 Homeworks Homeworks handed out Tuesdays or Thursdays due on the stated date, at midnight. Ten points per day late penalty No homework will be accepted more than three days late Homework MUST be typeset, and a single PDF file

  6. Collaboration + Cheating Groups of at most 3 people You may NOT share written work You may NOT use Google (or other search engines) You may NOT use solutions to previous years’ homework. You MUST sign the class honor code

  7. Textbook There is NO textbook for this class We have class notes in wiki format (soon) You too can edit the wiki!!!

  8. ((( ))) Feel free to ask questions

  9. 15-251 Cooking for Computer Scientists

  10. Pancakes With A Problem! Lecture 1 (August 24, 2010)

  11. The chefs at our place are sloppy: when they prepare pancakes, they come out all different sizes When 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) He does this by grabbing several from the top and flipping them over, repeating this (varying the number he flips) as many times as necessary

  12. How do we sort this stack?How many flips do we need?

  13. How do we sort this stack?How many flips do we need?

  14. Developing A Notation:Turning pancakes into numbers 5 52341 2 3 4 1

  15. How do we sort this stack?How many flips do we need? 52341

  16. 52341

  17. 4 Flips Are Sufficient 52341 14325 23415 43215 12345

  18. Best Way to Sort 52341 X = Smallest number of flips required to sort: Lower Bound 4 ?  X  ? Upper Bound

  19. 52341 X = Smallest number of flips required to sort: 4 is an upper bound: there exists a way to sort this stack using at most 4 flips. Lower Bound 4 ?  X  ? Which of the following statements would show a lower bound of 4? • there exists a way to sort this stack using at least 4 flips? Upper Bound • b. for every way to sort this stack, you use at least 4 flips.

  20. Can we do better? 52341

  21. Four Flips Are Necessary 52341 14325 41325 If we could do it in three flips: Flip 1 has to put 5 on bottom (else wewould take 3 flips just to get 5 to bottom) Flip 2 must bring 4 to top (if it didn’t, we would take more than three flips)

  22. Lower Bound Upper Bound 4  X  4 X = 4 52341 where X = Smallest number of flips required to sort:

  23. 1 2 3 5 4

  24. P5 = MAX over s 2 stacks of 5 of MIN # of flips to sort s 12345 1 2 3 5 4 1 2 52341 120 . . . . . . X120 X1 4 X2 X3 X119 5th Pancake Number P5 = Number of flips required to sort the worst case stack of 5 pancakes 54 3 21 54 3 12 1 2 4 3 5

  25. 5th Pancake Number Lower Bound 4 ?  P5 ? Upper Bound “There exists a 5-pancake stack which will make me take this much time” “For all 5-pancake stacks s, we can sort s in this much time” “For every 5-pancake stack, I will take this much time”

  26. Pn = MAX over s 2 stacks of n pancakes of MIN # of flips to sort s The number of flips required to sort the worst-case stack of n pancakes Pn =

  27. What is Pn for small n? Can you do n = 0, 1, 2, 3 ?

  28. Initial Values of Pn n 0 1 2 3 Pn 0 0 1 3

  29. P3 = 3 1 3 2 requires 3 Flips, hence P3 ≥ 3 ANY 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 two

  30. nth Pancake Number Pn = Number of flips required to sort the worst case stack of n pancakes Lower Bound ?  Pn ? Upper Bound

  31. Bracketing:What are the best lower and upper bounds that I can prove? ≤ f(x) ≤ ] [

  32. ?  Pn ? Try to find upper and lower bounds on Pn,for n > 3

  33. Bring-to-top Method Bring biggest to top Place it on bottom Bring next largest to topPlace second from bottom And so on…

  34. Upper Bound On Pn:Bring-to-top Method For n Pancakes If n=1, no work required — we are done! Otherwise, flip pancake n to top and then flip it to position n Now use: Bring To Top Method For n-1 Pancakes Total Cost: at most 2(n-1) = 2n –2 flips

  35. Better Upper Bound On Pn:Bring-to-top Method For n Pancakes If n=2, at most one flip and we are done! Otherwise, flip pancake n to top and then flip it to position n Now use: Bring To Top Method For n-1 Pancakes Total Cost: at most 2(n-2) + 1 = 2n – 3 flips

  36. ?  Pn 2n-3

  37. ?  Pn 2n-3 What other bounds can you prove on Pn?

  38. Breaking Apart Argument 9 16 Suppose a stack S has a pair of adjacent pancakes that will not be adjacent in the sorted stack Any sequence of flips that sorts stack S must have one flip that inserts the spatula between that pair and breaks them apart Furthermore, this is true of the “pair” formed by the bottom pancake of S and the plate

  39. n  Pn S 2468..n135..n-1 Suppose n is even S contains n pairs that will need to be broken apart during any sequence that sorts it 21 Detail: This construction only works when n>2

  40. n  Pn S 1357..n246..n-1 Suppose n is odd S contains n pairs that will need to be broken apart during any sequence that sorts it 132 Detail: This construction only works when n>3

  41. n  Pn 2n – 3 for n > 3 Bring-to-top is within a factor of 2 of the lower bound!

  42. From ANY stack to sorted stack in ≤ Pn ((( ))) From sorted stack to ANY stack in ≤ Pn ? Reverse the sequences we use to sort Hence, from ANY stack to ANY stack in ≤ 2Pn

  43. ((( ))) Can you find a faster way than 2Pn flips to go from ANY to ANY?

  44. ANY Stack S to ANY stack T in ≤ Pn S: 4,3,5,1,2 T: 5,2,4,3,1 3,5,1,2,4 1,2,3,4,5 “new T” Rename the pancakes in S to be 1,2,3,..,n Rewrite T using the new naming scheme that you used for S The sequence of flips that brings the sorted stack to the “new T” will bring S to T

  45. The Known Pancake Numbers 01345 Pn n 1234567891011121314151617 7891011 13141516171819

  46. P18 is Unknown It is either 20 or 21, we don’t know which. 1234…1718 = 18! orderings of 18 pancakes 18! = 6.402373 × 1015 To give a lower bound of 21 (say), we would have to find one of these stacks for which no sequences of 20 swaps sort the stack.

  47. Is This Really Computer Science?

More Related