1 / 78

CPSC 121: Models of Computation 2012 Summer Term 2

CPSC 121: Models of Computation 2012 Summer Term 2. Introduction to Induction Steve Wolfman. Outline. Prereqs, Learning Goals, and Quiz Notes Problems and Discussion Single-Elimination Tournaments Binary Trees A Pattern for Induction Induction on Numbers Next Lecture Notes.

sonora
Télécharger la présentation

CPSC 121: Models of Computation 2012 Summer Term 2

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. CPSC 121: Models of Computation2012 Summer Term 2 Introduction to Induction Steve Wolfman

  2. Outline • Prereqs, Learning Goals, and Quiz Notes • Problems and Discussion • Single-Elimination Tournaments • Binary Trees • A Pattern for Induction • Induction on Numbers • Next Lecture Notes

  3. Learning Goals: Pre-Class By the start of class, you should be able to: • Convert sequences to and from explicit formulas that describe the sequence. • Convert sums to and from summation/“sigma” notation. • Convert products to and from product/“pi” notation. • Manipulate formulas in summation/product notation by adjusting their bounds, merging or splitting summations/products, and factoring out values.

  4. Learning Goals: In-Class By the end of this unit, you should be able to: • Given a theorem to prove via induction and the insight into how the problem breaks down into one or more smaller problem(s), write out a complete proof strategy. • Prove naturally self-referential properties by induction. (That is, identify the “insight” and flesh out the strategy into a complete proof.) Discuss point of learning goals.

  5. Where We Are inThe Big Stories Theory Hardware How do we build devices to compute? Now: Taking a break in lecture. In lab, nearly at complete, working computer! (Although lab’s taking a break too, for regular expressions.) How do we model computational systems? Now: Developing a new proof technique that’s perfect for algorithms involving recursion (or iteration)... which is almost all interesting algorithms!

  6. Outline • Prereqs, Learning Goals, and Quiz Notes • Problems and Discussion • Single-Elimination Tournaments • Binary Trees • A Pattern for Induction • Induction on Numbers • Next Lecture Notes

  7. Single-Elimination Tournaments In each round teams play in pairs. Losing teams are eliminated. The tournament ends when only one team remains.

  8. What is a Tournament? Let’s think like CPSC 110ers… A tournament is one of:

  9. Single-Elimination Tournament Problem What’s the maximum number of teams in a 0-round single-elimination tournament? • 0 teams • 1 team • 2 teams • 3 teams • None of these Think: what does this correspond to in the data definition?

  10. Single-Elimination Tournament Problem What’s the maximum number of teams in a 1-round single-elimination tournament? • 0 teams • 1 team • 2 teams • 3 teams • None of these A “one round tournament” has only one set of games.A “two round tournament” has two sets of games (finals and semi-finals).

  11. Single-Elimination Tournament Problem What’s the maximum number of teams in a 2-round single-elimination tournament? • 0 teams • 1 team • 2 teams • 3 teams • None of these Would there be any “byes” in the tournament? A team with a “bye” gets to advance to the next round “for free”.

  12. Single-Elimination Tournament Problem What’s the maximum number of teams in an n-round single-elimination tournament? • nteams • 2n teams • n2 teams • 2n teams • None of these

  13. Tournament Step-by-Step Problem 2: Prove your result for... n = 0 n = 1 n = 2 n = 3 ...

  14. Tournament Logic If at most 2n-1teams can play in an (n-1)-round tournament, then at most 2n teams can play in an n-round tournament. If we want to prove this statement, which of the following techniques might we use? • Antecedent assumption • Witness proof • WLOG • Proof by cases • None of these

  15. Tournament Logic If at most 2n-1teams can play in an (n-1)-round tournament, then at most 2n teams can play in an n-round tournament. nN, Max(n-1,2n-1)  Max(n,2n). If we want to prove this statement, which of the following techniques might we use? • Antecedent assumption • Witness proof • WLOG • Proof by cases • None of these

  16. The “insight into how the problem breaks down” A tournament of n rounds is made up of two tournaments of (n-1) rounds, like how the Stanley Cup Finals is set “on top of” the “east half” and “west half” tournaments. One extra round:east winner vs. west winner

  17. The “insight into how the problem breaks down” The n-round tournament with the maximum number of teams is made from two (n-1)-round tournaments with the maximum number of teams.

  18. Completing (?) the Proof Theorem: if at most 2n-1teams can play in an (n-1)-round tournament, then at most 2n teams can play in an n-round tournament. Proof: Assume at most 2n-1 teams can play in an (n-1)-round tournament. An n-round tournament is two (n-1)-round tournaments where the winners play each other (since there must be a single champion). By assumption, each of these may have at most 2n-1 teams. So, the overall tournament has at most 2*2n-1 = 2nteams. QED!

  19. Are We Done? Here’s the logical structure of our theorem:nN, Max(n-1,2n-1)  Max(n,2n). Does that prove nN, Max(n,2n)? • Yes. • No. • I don’t know. P.S. Is this really what we proved?Is our theorem true for all non-negative integers?

  20. Are We Done? Here’s the logical structure of our theorem:nN, Max(n-1,2n-1)  Max(n,2n). Have we handled both cases of our data definition? • Yes. • No. • I don’t know.

  21. What More Do We Need? This parallels the self-referential variant of our tournament “data definition”:nN, (n > 0)  Max(n-1,2n-1)  Max(n,2n). Why doesn’t this work for 0? What do we do about the base case of our data definition?

  22. Completing (?) the Proof (again) Base Case Theorem: At most one team can play in a 0-round tournament. Proof: Every tournament must have one unique winner. A zero-round tournament has no games; so, it can only include one team: the winner. QED! Everybody’s a winner. That’s so sweet 

  23. Now Are We Done? Here’s the logical structure of our theorems:Max(0,1). nZ0, (n > 0)  Max(n-1,2n-1)  Max(n,2n). Do these prove nZ0, Max(n,2n)? • Yes. • No. • I don’t know.

  24. One Extra Step We’ll Do Really, we are done. But just to be thorough, we’ll add: Termination:n is a non-negative integer, and each application of the inductive step reduces it by 1. Therefore, it must reach our base case (0) in a finite number of steps.

  25. Step-by-Step? Here’s the logical structure of our theorems:Max(0,20). nZ0, (n > 0)  Max(n-1,2n-1)  Max(n,2n). Do these prove Max(1,21)? • Yes. • No. • I don’t know.

  26. Step-by-Step? Here’s the logical structure of our theorems:Max(0,20). nZ0, (n > 0)  Max(n-1,2n-1)  Max(n,2n). Plus, we know Max(1,21). Do all of these prove Max(2,22)? • Yes. • No. • I don’t know.

  27. Step-by-Step? Here’s the logical structure of our theorems:Max(0,20). nZ0, (n > 0)  Max(n-1,2n-1)  Max(n,2n). Plus, we know Max(1,21) and Max(2,22).Do all of these prove Max(3,23)? • Yes. • No. • I don’t know.

  28. Step-by-Step? Here’s the logical structure of our theorems:Max(0,20). nZ0, (n > 0)  Max(n-1,2n-1)  Max(n,2n). From this, can we prove Max(n,2n)for any particular integer n? • Yes. • No. • I don’t know.

  29. Tournament Proof Summary Theorem: At most 2n teams play in an n-round tournament. Proof: We proceed by induction. Base Case: A zero-round tournament has no games and so can only include one (that is, 20) team: the winner. So, at most 20 teams play in a 0-round tournament.  Induction Hypothesis: WLOG, for an arbitrary integer n > 0, assume at most 2n-1teams play in an (n-1)-round tournament. Inductive Step: An n-round tournament is two (n-1)-round tournaments where the winners play each other. By the IH, each of these has at most 2n-1 teams. So, the overall tournament has at most 2*2n-1 = 2nteams.  Termination:n is a non-negative integer, and each application of the inductive step reduces it by 1. Therefore, it must reach our base case (0) in a finite number of steps.  QED

  30. Outline • Prereqs, Learning Goals, and Quiz Notes • Problems and Discussion • Single-Elimination Tournaments • Binary Trees • A Pattern for Induction • Induction on Numbers • Next Lecture Notes

  31. “Binary Trees” A “binary tree” is either a leaf or a root “node” and two children, each of which is a binary tree. (Note: a slightly different definition is common, but less convenient.) 10 5 20 15 2 9 7 17 (They let us do some cool CS things... see CS110, 210, 221.)

  32. Binary Tree Data Definition A binary-tree is one of: • A leaf • (make-node binary-tree binary-tree number) 10 5 20 15 2 9 7 17

  33. Binary Trees’ Height A binary tree’s “height” is the maximum number of steps it takes to get from the root down to a node with only leaves as children. This one’s height is: • 0 • 1 • 2 • 3 • 4 10 5 20 15 2 9 7 17

  34. Binary Trees’ Height Problem 1:What’s the maximum number of nodes in a binary tree of height n? 10 5 20 15 2 9 7 17

  35. Binary Trees’ Height Problem 2:Prove your result. 10 5 20 15 2 9 7 17

  36. Binary Trees, Take Two Problem 1:Give an algorithm to determine the height of a binary tree. Problem 2: Prove that your algorithm is correct. 10 5 20 15 2 9 7 17

  37. Worked: Algorithm for Height Height(t): Is t a leaf? Yes: evaluate to -1 No: recursively find the height of each subtree hl and hr and evaluate to max(hl, hr) + 1. 10 5 20 15 2 9 7 17 How big are the subtrees?We need to assume the algorithm works on trees of “those sizes”.

  38. Worked: Proof of Algorithm’s Correctness Proof: We proceed by induction. Base case: On a leaf, our algorithm yields -1. We simply make this correct by definition. (Or, you can imagine we go “up one level” to get to a node.) Induction Hypothesis: For an arbitrary (finite-sized) non-leaf tree t, assume our algorithm works correctly on all trees smaller than t. Inductive step: t is not a leaf; so, our algorithm finds the height of each subtreehl and hr. These heights are correct by assumption, since the subtrees must be smaller than t (lacking at least t itself!). To reach a node with only leaves as children, we go into either the left or right subtree. The length of the path through the left subtree is therefore hl+1, with the +1 for the step down into that subtree. Similarly, the right path is hr+1. The height is the larger of these possible paths; so, it’s max(hl+1,hr+1) = max(hl,hr) + 1, which is what our algorithm evaluates to. Termination: We call this only on finite trees, and we reduce the size of the tree by at least one node at each inductive step. Thus, we eventually reach a leaf. QED 10 5 20 15 2 9 7 17

  39. Outline • Prereqs, Learning Goals, and Quiz Notes • Problems and Discussion • Single-Elimination Tournaments • Binary Trees • A Pattern for Induction • Induction on Numbers • Next Lecture Notes

  40. An Induction Proof Pattern Type of Problem: Prove some property of a structure that is naturally defined in terms of itself. Part 1: Insight: how does the problem “break down” in terms of smaller pieces? Induction doesn’t help you with this part. It is not a technique to figure out patterns, only to prove them. Part 2: Proof. Establish that the property is true for your base case(s). Establish that it is true at each step of construction of a more complex structure. Establish that you could create a finite proof out of these steps for any value of interest (termination).

  41. A Pattern For Induction Theorem:At most 2n teams play in an n-round tournament. Proof: We proceed by induction. Base Case: A zero-round tournament has no games and so can only include one (that is, 20) team: the winner. So, at most 20 teams play in a 0-round tournament.  Base Case(s):A zero-round tournament has no games and so can only include one (that is, 20) team: the winner. So, at most 20 teams play in a 0-round tournament. Induction Hypothesis: WLOG, for an arbitrary integer n > 0, assume at most 2n-1teams play in an (n-1)-round tournament. Inductive Step: An n-round tournament is two (n-1)-round tournaments where the winners play each other. By the IH, each of these has at most 2n-1 teams. So, the overall tournament has at most 2*2n-1 = 2nteams. Termination:n is a non-negative integer, and each application of the inductive step reduces it by 1. Therefore, it must reach our base case (0) in a finite number of steps. QED

  42. A Pattern For Induction Theorem:P(n) is true for all n some smallest number. Proof: We proceed by induction on n. Base Case(s) (P(.) is true for a few simple cases): Prove with our other techniques. Which cases? Almost certainly the some smallest number. Maybe more. Make notes on which you need, as with a witness proof! Induction Hypothesis: For an arbitrary n > the largest of your base cases: assume P(.) is true for whichever cases you need. Inductive Step (P(n) is true): WLOG, let n be greater than the largest of your base cases. Assume P(.) is true for whichever cases you need. Break P(n) down in terms of the smaller case(s).The smaller cases are true, by assumption. Build back up to show that:P(n) is true. Termination:n is a ___________, and each application of the inductive step ___________. Therefore, it must reach (one of) our base case(s) in a finite number of steps (without “jumping past”). QED

  43. A Pattern For Induction  Which base cases? Almost certainly the smallest n. Otherwise, you don’t know yet. Do the rest of the proof now. Come back to the base case(s) when you know which one(s) you need!

  44. A Pattern For Induction  Which values are we going to assume P(.) is true for? Whichever we need. How do we know the ones we need? We don’t, yet. So… do the rest of the proof now. Come back to the assumption when you know which one(s) you need!

  45. A Pattern For Induction  What must n be larger than? The largest of your base cases. (Why? So you don’t assume the theorem true for something that’s too small, like a negative one round tournament.) But, you don’t know all your base cases yet. So…do the rest of the proof now. Come back to this bound once you know your base case(s).

  46. A Pattern For Induction  How do we break the problem down in terms of smaller cases? THIS is the real core of every induction problem. Figure this out, and you’re ready to fill in the rest of the blanks!

  47. A Pattern For Induction P(n) is ______________. Theorem: P(n) is true for all n  _______. Proof: We proceed by induction on n. Base Case(s) (P(.) is true for _______):Prove each base case via your other techniques. Induction Hypothesis: For an arbitrary n > _______, assume P(.) is true for ___________. Inductive Step: Break P(n) down in terms of the smaller case(s). The smaller cases are true, by the IH. Build back up to show that P(n) is true. Termination:nis a ___________, and each application of the inductive step ___________. Therefore, it must reach (one of) our base case(s) in a finite number of steps (without “jumping past”). QED

  48. Examples: Breaking down into a problem one smaller You want to prove P(n) for all n  1. You know that P(n) is true if P(n-1) is true. How do we fill in the blanks? This is the most common style of insight, and the same as we had in our “# teams in a tournament” question. (It’s called “weak induction”.)

  49. Examples: Breaking down into a problem one smaller You want to prove P(n) for all n  1. You know that P(n) is true if P(n-1) is true. How do we fill in the blanks? Theorem: P(n) is true for all n  _______.

  50. Examples: Breaking down into a problem one smaller You want to prove P(n) for all n  1. You know that P(n) is true if P(n-1) is true. How do we fill in the blanks? Theorem: P(n) is true for all n  1. Proof: We proceed by induction on n. Base Case(s) (P(.) is true for _______):Prove each base case via your other techniques.

More Related