cpsc 121 models of computation
play

CPSC 121: Models of Computation Convert sequences to and from - PowerPoint PPT Presentation

Pre-Class Learning Goals By the start of class, you should be able to CPSC 121: Models of Computation Convert sequences to and from explicit formulas that describe the sequence. Convert sums to and from summation/ notation.


  1. Pre-Class Learning Goals  By the start of class, you should be able to CPSC 121: Models of Computation  Convert sequences to and from explicit formulas that describe the sequence.  Convert sums to and from summation/Σ notation.  Convert products to and from product/ Π notation.  Manipulate formulas in summation/product notation by adjusting their bounds, merging or splitting Unit 9a summations/products, and factoring out values. Mathematical Induction – Part 1  Given a theorem to prove and the insight into how to break the problem down in terms of smaller problems , write out the skeleton of an inductive: the base case(s),the induction hypothesis, and the inductive step Based on slides by Patrice Belleville and Steve Wolfman 2 Quiz 9 Feedback In-Class Learning Goals  Generally:  By the end of this unit, you should be able to:  Formally prove properties of the non-negative integers (or a  Issues: subset like integers that have appropriate self-referential structure) — including both equalities and inequalities — using either weak or strong induction as needed.  Critique formal inductive proofs to determine whether they are valid and where the error(s) lie if they are invalid.  Essay Question:  As usual, we will revisit the open-ended question shortly. 3 4 1

  2. ? ? Addressing the Course Big Questions Outline  CPSC 121: the BIG questions:  Introduction and Discussion  How can we convince ourselves that an algorithm  Example: single-elimination tournaments . does what it's supposed to do?  How do we determine whether or not one algorithm is  Example: max swaps for sorting n items better than another one?  Mathematical induction is a very useful tool when  A Pattern for Induction proving the correctness or efficiency of an  Induction on Numbers algorithm.  We will see several examples of this. 5 6 How do we start? Example: Single-Elimination Tournament  Problem: single-elimination tournament  Teams play one another in pairs  Let’s try some examples with small numbers  The winner of each pair advances to the next round  The tournament ends when only one team remains. Los Angeles Vancouver Los Angeles Toronto Toronto St. Louis Los Angeles Montréal Pittsburgh New York Isl. New York Isl. Montréal Montréal Buffalo Round 2 Round 3 Round 1 7 8 2

  3. Example (cont`) Example (cont`)  What is the maximum number of teams in a 0 -round  What is the maximum number of teams in a 1 -round single-elimination tournament ? single-elimination tournament ? A. 0 teams A. 0 teams B. 1 team B. 1 team C. 2 teams C. 2 teams D. 3 teams D. 3 teams E. None of the above. E. None of the above. 9 10 Example (cont`) Example (cont`)  What is the maximum number of teams in a 2 -round  What is the maximum number of teams in a n -round single-elimination tournament ? single-elimination tournament ? A. 0 teams A. n B. 1 team B. 2n C. 2 teams C. n 2 D. 3 teams D. 2 n E. None of the above. E. None of the above. 11 12 3

  4. Case for n-1  Case for n How can we prove it?  If at most 2 n-1 teams can participate in a tournament  How can we prove it for every n ? with n-1 rounds, then at most 2 n teams can participate  We will use a technique called mathematical induction. in a tournament with n rounds?  We show some basic cases first (for 0,1,2 )  If we want to prove this statement, which of the  Then we show that if the statement is true for case n-1 following techniques might we use? then it is true for case n A. Antecedent assumption B. Witness proof  Basic Cases how many we need?): C. WLOG  n= 0  n = 1 D. Proof by cases  … E. None of the above. 13 14 Working out the proof: Completing the proof:  Theorem : if at most 2 n -1 teams can play in an ( n -1 ) -  Proof (with holes): round tournament, then at most 2 n teams can play in  Consider an unspecified tournament with n-1 rounds. an n -round tournament. Assume that  Proof:  How many teams we need to have a tournament with n  Assume at most 2 n -1 teams can play in an ( n -1 ) -round rounds? tournament.  We can think of a tournament with n rounds as follows:  An n -round tournament is two ( n -1)-round tournaments o Two tournaments with n-1 rounds proceed in parallel. where the winners play each other (since there must be a single champion). o The two winners then  By assumption, each of these may have at most 2 n -1 teams. So, the overall tournament has at most 2*2 n -1 = 2 n teams.  Since each tournament with n-1 rounds has QED! 15 16 4

  5. Are We Done? What More Do We Need? Here’s the logical structure of our original theorem: We need to adjust it to  n  N, Max( n -1,2 n -1 )  Max( n ,2 n ) .  n  N, (n > 0)  Max( n -1,2 n -1 )  Max( n ,2 n ) . Does that prove  n  N, Max( n ,2 n ) ? Why doesn’t this work for 0? a. Yes. What do we do about the base case of our data definition? b. No. c. I don’t know . 17 18 Completing (?) the Proof (again) Now Are We Done? Here’s the logical structure of our theorems: Base Case Theorem : At most one team can play in a 0- (1) Max(0,1) . round tournament. (2)  n  Z 0 , (n > 0)  Max( n -1,2 n -1 )  Max( n ,2 n ) . Proof : Every tournament must have one unique winner. A zero-round tournament has no games; so, it can only Do these prove  n  Z 0 , Max( n ,2 n ) ? include one team: the winner. QED! a. Yes. No. b. I don’t know. c. 19 20 5

  6. One Extra Step We’ll Do Step-by-Step? Here’s the logical structure of our theorems: Really, we are done. Max(0,2 0 ) .  n  Z 0 , (n > 0)  Max( n -1,2 n -1 )  Max( n ,2 n ) . But just to be thorough, we’ll add: Termination: n is a non-negative integer, and each Do these prove Max(1,2 1 ) ? application of the inductive step reduces it by 1. Therefore, it must reach our base case (0) in a finite Yes. a. number of steps. No. b. I don’t know. c. 21 22 Step-by-Step? Step-by-Step? Here’s the logical structure of our theorems: Here’s the logical structure of our theorems: Max(0,2 0 ) . Max(0,2 0 ) .  n  Z 0 , (n > 0)  Max( n -1,2 n -1 )  Max( n ,2 n ) .  n  Z 0 , (n > 0)  Max( n -1,2 n -1 )  Max( n ,2 n ) . Plus, we know Max(1,2 1 ) . Plus, we know Max(1,2 1 ) and Max(2,2 2 ) . Do all of these prove Max(2,2 2 ) ? Do all of these prove Max(3,2 3 ) ? a. Yes. a. Yes. No. No. b. b. I don’t know. I don’t know. c. c. 23 24 6

  7. Step-by-Step? Tournament Proof Summary Here’s the logical structure of our theorems: Theorem : At most 2 n teams play in an n-round tournament. Max(0,2 0 ) . Proof : We proceed by induction.  n  Z 0 , (n > 0)  Max( n -1,2 n -1 )  Max( n ,2 n ) . Base Case : A zero-round tournament has no games and so can only include one (that is, 2 0 ) team: the winner. So, at most 2 0 teams play in a 0-round tournament.  Induction Hypothesis: WLOG, for an arbitrary integer n > 0, From this, can we prove Max( n ,2 n ) assume at most 2 n -1 teams play in an ( n -1 ) -round tournament. for any particular integer n ? Inductive Step: We’ll show it is true for n. An n -round tournament is two ( n -1)-round tournaments where the winners Yes. a. play each other. By the IH, each of these has at most 2 n -1 teams. So, the overall tournament has at most 2*2 n -1 = 2 n No. b. teams.  I don’t know. c. [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 25 26 Outline Example 2: Sorting n items   Introduction and Discussion  Example: single-elimination tournaments .  Example: max swaps for sorting n items  A Pattern for Induction  Induction on Numbers 27 28 7

  8. Example 2: Sorting n items Example 1: Sorting n items   29 30 Outline An Induction Proof Pattern Type of Problem: Prove some property of a structure  Introduction and Discussion that is naturally defined in terms of itself.  Example: single-elimination tournaments. Part 1: Insight: how does the problem “break down” in terms of smaller pieces? Induction doesn’t help you  Example: max swaps for sorting n items with this part. It is not a technique to figure out  A Pattern for Induction patterns, only to prove them. Part 2: Proof. Establish that the property is true for your  Induction on Numbers 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 ). 32 31 8

Recommend


More recommend