Presentation is loading. Please wait.

Presentation is loading. Please wait.

Module 9: Mathematical Induction

Similar presentations


Presentation on theme: "Module 9: Mathematical Induction"— Presentation transcript:

1 Module 9: Mathematical Induction
12/21/2017 Module 9: Mathematical Induction 1 1

2 Module 9: Announcements
12/21/2017 Module 9: Announcements There is a chance that this Friday’s class may be cancelled. Assignment #4 is due Thursday March 16th at 4pm. Midterm #2 Monday March 20th, 2017 from 7pm to 9pm Read the Piazza post. Let us know if you have a conflict. 2 2

3 Learning goals: pre-class
12/21/2017 Learning goals: pre-class Epp 4th section 5.1: 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 summations/products, and factoring out values. Be able to take a sequence and convert it to a formula, or vice versa. Should understand summation and product notations, and be able to manipulate them. 3 3

4 Learning goals: pre-class
12/21/2017 Learning goals: pre-class Epp 4th sections 5.2 to 5.4: Given a theorem to prove stated in terms of its induction variable (i.e., usually, in terms of n), write out the skeleton of an inductive proof including: the base case(s) that need to be proven, the induction hypothesis, and the inductive step that needs to be proven. 4 4

5 Learning goals: in-class
12/21/2017 Learning goals: in-class By the end of this module, you should be able to: Establish properties of self-referential structures using inductive proofs that naturally build on those self-references. Critique formal inductive proofs to determine whether they are valid and where the error(s) lie if they are invalid. Prove properties of the non-negative integers (or a subset) with appropriate self-referential structure using weak or strong induction as needed. Know how to use weak and strong induction to prove properties of integers and algorithms. 5 5

6 12/21/2017 The BIG questions: How can we convince ourselves that an algorithm does what it's supposed to do? How do we determine whether or not one algorithm is better than another one? Mathematical induction is a very useful tool when proving the correctness or efficiency of an algorithm. We will see several examples of this. 6 6

7 Module 9 outline Example: single-elimination tournaments.
12/21/2017 Module 9 outline Example: single-elimination tournaments. Defining and validating mathematical induction. More examples where we can use induction. A slightly different type of induction. 7 7

8 Single-elimination tournaments
12/21/2017 Single-elimination tournaments Problem: single-elimination tournament Teams play one another in pairs The winner of each pair advances to the next round 1993 Stanley Cup Competition After 4 rounds, Montreal won the Stanley Cup. Los Angeles Vancouver Los Angeles Toronto Toronto St. Louis Los Angeles Montréal Pittsburgh New York Isl. Montréal New York Isl. Montréal Montréal Buffalo Round 2 Round 3 Round 4 8 8

9 Single-elimination tournaments
12/21/2017 Single-elimination tournaments If we have n rounds of playoffs, how many teams can participate? n 2n n2 None of the above. Let’s prove this using mathematical induction. Answer is (d). 2^n. 9 9

10 12/21/2017 The inductive step If 2n teams can participate in a playoff with n rounds, how many teams can participate in a playoff with 2n+1 rounds? 2n +1 2n+1 (n+1)2 None of the above. Answer is (b). 2^(n+1) A tournament with n rounds and a tournament with n+1 rounds. If t teams can play in a playoff with n rounds, then how many teams can participate in a playoff with n+1 rounds? 10 10

11 12/21/2017 The inductive step Theorem: If 2n teams can participate in a playoff of n rounds, then 2n+1 teams can participate in a playoff of n+1 rounds. Let 𝑃(𝑥,𝑦) be true if y teams can play in x rounds. In predicate logic: ∀𝑛∈𝑍,𝑃(𝑛, 2 𝑛 )→𝑃(𝑛+1, 2 𝑛+1 ) Let’s prove this. With n rounds, we have t teams, and we have a final winner. Now we have one more round. What can we do? Our winner can compete with someone else to decide who’s the final winner. That someone else can be a winner from another tournament with n rounds, running in parallel. 11 11

12 12/21/2017 The inductive step Theorem: If 2n teams can participate in a playoff of n rounds, then 2n+1 teams can participate in a playoff of n+1 rounds. Proof: Consider an unspecified playoff with n rounds. Assume that 2n teams can participate in a playoff of n rounds. We can think of a playoff with n+1 rounds as follows: Two playoffs with n rounds proceed in parallel. The two winners then complete in one more round to determine the winner. Since each playoff with n rounds has 2n teams, a playoff with n+1 rounds has 2n+1 teams. QED With n rounds, we have t teams, and we have a final winner. Now we have one more round. What can we do? Our winner can compete with someone else to decide who’s the final winner. That someone else can be a winner from another tournament with n rounds, running in parallel. 12 12

13 The complete induction proof
Theorem: For any positive integer n, at most 2n teams can participate in a playoff of n rounds. In predicate logic, the theorem becomes: ∀𝑛∈𝑍,𝑃(𝑛, 2 𝑛 ) Proof: We prove this by induction. Base case: Induction step:

14 What did we prove with induction?
12/21/2017 What did we prove with induction? Theorem: ∀𝑛∈𝑍,𝑃 𝑛, 2 𝑛 ≡𝑃 1,2 ∧𝑃 2,4 ∧𝑃 3,8 ∧𝑃 4,16 … Proof: We prove this by induction. Base case: 𝑛=1, 𝑃(1,2) is true. Induction step: We will prove that ∀𝑛∈𝑍,𝑃 𝑛, 2 𝑛 →𝑃 𝑛+1, 2 𝑛+1 ≡𝑃(1,2)→ 𝑃(2,4) ∧𝑃 2,4 →𝑃(3,8)∧𝑃 3,8 →𝑃(4,16)∧… Recall the universal modus ponens rule. The statement that we just proved is similar to the second premise in this rule. Let’s see how. Define a predicate, P(t, n), which says that t teams can participate in a playoff with n rounds. We just showed that if t teams can participate in a playoff with n rounds, then 2t teams can participate in a playoff with n+1 rounds. And this is true as long as t and n are positive integers. Doesn’t make sense to have a negative number of teams or rounds. 14 14

15 What did we prove with induction?
12/21/2017 What did we prove with induction? 𝑃(1,2) 𝑃(1,2)→𝑃(2,4) 𝑃(2,4) by modus ponens 𝑃(2,4) 𝑃(2,4)→𝑃(3,8) 𝑃(3,8) by modus ponens 𝑃(3,8) 𝑃(3,8)→𝑃(4,16) 𝑃(4,16) by modus ponens … Therefore, we have shown that: 𝑃 1,2 ∧𝑃 2,4 ∧𝑃 3,8 ∧𝑃 4,16 ∧… ≡∀𝑛∈𝑍,𝑃 𝑛, 2 𝑛 Recall the universal modus ponens rule. The statement that we just proved is similar to the second premise in this rule. Let’s see how. Define a predicate, P(t, n), which says that t teams can participate in a playoff with n rounds. We just showed that if t teams can participate in a playoff with n rounds, then 2t teams can participate in a playoff with n+1 rounds. And this is true as long as t and n are positive integers. Doesn’t make sense to have a negative number of teams or rounds. 15 15

16 The connection to recursion
12/21/2017 The connection to recursion For an unspecified positive integer n To prove 𝑃(𝑛+1, 2 𝑛+1 ): We can instead prove 𝑃(𝑛, 2 𝑛 ). This is a recursive call. Induction is more or less the same as recursion! A fun example involving induction: Reducing it to a simpler problem. What if we can figure out the number of teams for n rounds. If we can do that, then by this implication, then we can deduce the number of teams for n+1 rounds. Induction is basically the same as recursion. We are solving a hard problem by reducing it to an easier problem and solving the easier the problem instead. 16 16

17 Module 9 outline Example: single-elimination tournaments.
12/21/2017 Module 9 outline Example: single-elimination tournaments. Defining and validating mathematical induction. More examples where we can use induction. A slightly different type of induction. 17 17

18 Defining and validating M.I.
12/21/2017 Defining and validating M.I. Define Q(n) by: Q(n): P(2n,n) In the previous example, we proved Q(1) ∀n ∈ Z+, Q(n) → Q(n+1) and deduced that ∀n ∈ Z+, Q(n) Why is this a valid proof technique? 18 18

19 Defining and validating M.I.
12/21/2017 Defining and validating M.I. Theorem: Q(1) ^ (∀n ∈ Z+, Q(n) → Q(n+1)) → ∀n ∈ Z+, Q(n) Proof: We use a proof by contradiction. Suppose that the premises hold, but that ∀n ∈ Z+, Q(n) is false. There is at least one value of n for which Q(n) does not hold. Let y be the smallest such value. Clearly y > 1, so y – 1 ∈ Z+. Can y be 1? Q(1) is the first premise. By proof by contradiction, we assume it is true. So we assume that Q(1) must be true. y can be as small as 2, but can be much bigger also. 19 19

20 Defining and validating M.I.
12/21/2017 Defining and validating M.I. Proof (continued): Because y is the smallest value for which Q(n) is false, and y – 1 ∈ Z+, Q(y - 1) is true. But then the 2nd premise implies that Q(y) is true, a contradiction (since we assumed Q(y) was false). Therefore the conclusion must be true, that is ∀n ∈ Z+, Q(n) holds. Since y is the smallest value for which Q(n) is false. What about y-1? Q(y-1)? Q(y-1) must be true. Do we have a problem? Q(y-1) is true. Q(y) is false? 20 20

21 Defining and validating M.I.
12/21/2017 Defining and validating M.I. So a proof by mathematical induction has One (or more) base case(s): Q(1) Usually very straightforward to prove. An induction step: ∀n ∈ Z+, Q(n) → Q(n+1) We can use any proof technique we know for it. Usually a direct proof will work well. Point out we will look at a more general form soon. 21 21

22 Module 9 outline Example: single-elimination tournaments.
12/21/2017 Module 9 outline Example: single-elimination tournaments. Defining and validating mathematical induction. More examples where we can use induction. A slightly different type of induction. 22 22

23 Ordering students using adjacent swaps
12/21/2017 Ordering students using adjacent swaps We want to order a group of 5 students in order of day of birth We are only allowed to swap pairs of adjacent students. We claimed the maximum number of swaps for n students is n(n-1)/2. 23 23

24 How many swaps do we need?
12/21/2017 How many swaps do we need? Let’s place students from left to right. The students already placed are ordered by day of birth. We swap each new student with his/her neighbour until he/she is at the right place. The ith student may be swapped with all previous (i-1) students. So the total number of swaps is Theorem 1: Suppose that students are initially ordered in reverse. This is the worst case. Each student needs to be swapped with all previous students. With 5 students, the total number of swaps is We claim that this total is 5 (5 – 1) / 2 Let’s prove this. 𝑖=0 𝑛−1 𝑖 ∀𝑛∈ 𝑍 + , 𝑖=0 𝑛−1 𝑖 = 𝑛 𝑛−1 2 24 24

25 Theorem 1: Let’s parse the theorem first. One way to think about it:
12/21/2017 Theorem 1: ∀𝑛∈ 𝑍 + , 𝑖=0 𝑛−1 𝑖 = 𝑛 𝑛−1 2 Let’s parse the theorem first. One way to think about it: Theorem 1: 0=0∧0+1=1∧0+1+2=3∧ =6∧ =10∧… Another way to think about it: Let Theorem 1: 𝑃(1)∧𝑃(2)∧ 𝑃(3)∧ 𝑃(4)∧… Unpacking the theorem, it is a giant AND. P 𝑛 ≡ 𝑖=0 𝑛−1 𝑖 = 𝑛 𝑛−1 2 25 25

26 Theorem 1: Which base case(s) do we need to prove? n = 0 n = 1 n = 2
12/21/2017 Theorem 1: ∀𝑛∈ 𝑍 + , 𝑖=0 𝑛−1 𝑖 = 𝑛 𝑛−1 2 Which base case(s) do we need to prove? n = 0 n = 1 n = 2 n = 0 and n = 1 n = 1 and n = 2 Both b and e are correct answers. Explain e a bit later. 26 26

27 Theorem 1: Both of a and b are correct.
12/21/2017 Theorem 1: ∀𝑛∈ 𝑍 + , 𝑖=0 𝑛−1 𝑖 = 𝑛 𝑛−1 2 What do we need to prove in the induction step? Both of a and b are correct. Neither of a and b are correct. ∀𝑛∈ ℤ + 𝑖=0 𝑛−1 𝑖 = 𝑛 𝑛−1 2 → 𝑖=0 𝑛 𝑖 = 𝑛+1 𝑛 2 ∀𝑛∈ ℤ + , 𝑖=0 𝑛−1 𝑖 = 𝑛 𝑛−1 2 → ∀𝑛∈ ℤ + , 𝑖=0 𝑛 𝑖 = 𝑛+1 𝑛 2 Answer is (a). 27 27

28 What is induction proving?
Base case: 𝑃 1 Induction step: 𝑃(1)→𝑃(2) ∧𝑃 2 →𝑃 3 ∧𝑃 3 →𝑃 4 ∧… Combining the two, we have proven that 𝑃(1) ∧𝑃 2 ∧𝑃 3 ∧𝑃 4 ∧… Re-iterate the clicker question answers. Induction is like playing dominos. Theorem: Every domino will fall. Base case: I will go push the first domino to make sure that it falls. Induction step: I will lay out the dominos such that, if one domino falls, the next domino will also fall. This makes sure that the chain reaction happens.

29 A fun video about induction…
feature=related

30 Theorem 1: Proof: We prove the theorem by induction. Base case: n = 1
12/21/2017 Theorem 1: ∀𝑛∈ 𝑍 + , 𝑖=0 𝑛−1 𝑖 = 𝑛 𝑛−1 2 Proof: We prove the theorem by induction. Base case: n = 1 Clearly, with only 1 student, no swap is needed: which is equal to 1*(1-1)/2 = 0 Induction step: Pick an unspecified n ≥ 1. Assume that when we have n students, we need at most n(n-1)/2 swaps. Equivalently we assume that This is called the Induction Hypothesis. 𝑖=0 𝑛−1 𝑖 = 𝑛 𝑛−1 2 30 30

31 Theorem 1: Proof (continued) Induction step (continued)
12/21/2017 Theorem 1: ∀𝑛∈ 𝑍 + , 𝑖=0 𝑛−1 𝑖 = 𝑛 𝑛−1 2 Proof (continued) Induction step (continued) For n+1 students, we need at most swaps. By the induction hypothesis, this is equal to swaps, as required for the induction step. Hence by the principle of M.I., the theorem holds. QED 𝑖=0 𝑛 𝑖 = 𝑖=0 𝑛−1 𝑖 +𝑛 Note: there is a much simpler proof of this fact. Sum = (n-2) + (n-1) Sum = (n-1) + (n-2) So 2*Sum = (n-1)n Sum = (n-1)n/2 𝑛 𝑛−1 2 +𝑛= 𝑛+1 𝑛 2 31 31

32 Induction is like recursion
Where is our recursive call in the induction proof? Base case: Induction step: consider an unspecified positive integer n. Induction step: Assume that… (where we stated our induction hypothesis) Induction step: The algebra where we applied our induction hypothesis Induction step: some other algebra steps Answer is (d). When we applied our induction hypothesis, we are trying to break the problem up into smaller and simpler problems.

33 Induction is like recursion
I don’t know how to calculate … + (n-2) + (n-1) + n However, if you tell me how to calculate (n-2) + (n-1) I can calculate the first sum as follows = ( (n-2) + (n-1)) + n

34 Review questions on induction
Give me 3 critical components of an induction proof. When we are completing the induction step, what is our most important goal in life? Writing an induction proof is like playing dominos. What does the base case correspond to? What does the induction step correspond to? Induction is similar to recursion. Which part of an induction proof corresponds to the recursive call?

35 Geometric series Theorem 2:
12/21/2017 Geometric series ∀𝑡∈𝑁, 𝑖=0 𝑡 5 𝑖 = 5 𝑡+1 −1 5−1 Theorem 2: These summations occur frequently when we need to determine the running time of divide- and-conquer algorithms. 35 35

36 Theorem 2: What should we prove in the base case? t = -1 t = 0 t = 1
∀𝑡∈𝑁, 𝑖=0 𝑡 5 𝑖 = 5 𝑡+1 −1 5−1 What should we prove in the base case? t = -1 t = 0 t = 1 t = 2 t = 3

37 Theorem 2: Both of a and b are correct.
∀𝑡∈𝑁, 𝑖=0 𝑡 5 𝑖 = 5 𝑡+1 −1 5−1 What do we need to prove in the induction step? Both of a and b are correct. Neither of a and b are correct. ∀𝑡∈𝑁, 𝑖=0 𝑡 5 𝑖 = 5 𝑡+1 −1 5−1 → 𝑖=0 𝑡+1 5 𝑖 = 5 𝑡+2 −1 5−1 ∀𝑡∈𝑁, 𝑖=0 𝑡 5 𝑖 = 5 𝑡+1 −1 5−1 → ∀𝑡∈𝑁, 𝑖=0 𝑡+1 5 𝑖 = 5 𝑡+2 −1 5−1 Theorem: P(0) ^ P(1) ^ P(2) ^ P(3) ^ … Option (a): P(0) -> P(1) ^ P(1) -> P(2) ^ P(2) -> P(3) ^ … Option (b): (P(0) ^ P(1) ^ P(2) ^ P(3) ^ …) -> (P(1) ^ P(2) ^ P(3) ^ P(4) ^ ...) This option says: if the equation is true for all natural numbers, then it is true for all positive integers. If we assume that the equation is true for all natural numbers, this is same as assuming that our theorem is true.

38 Theorem 2: Proof: Base case: t = 0 Induction step:
12/21/2017 ∀𝑡∈𝑁, 𝑖=0 𝑡 5 𝑖 = 5 𝑡+1 −1 5−1 Theorem 2: Proof: Base case: t = 0 The summation is 50 = 1, and Induction step: Consider an unspecified natural number t. Assume that … We need to prove that … Hence by the principle of M.I., the theorem holds. QED 5 1 −1 5−1 =1 ∑ 𝑖=0 𝑡+1 𝑎 𝑖 = ∑ 𝑖=0 𝑡 𝑎 𝑖 + 𝑎 𝑡+1 = 𝑎 𝑡+1 −1 𝑎−1 + 𝑎 𝑡+1 = 𝑎 𝑡+1 −1+ 𝑎 𝑡+1 𝑎−1 𝑎−1 = 𝑎 𝑡+2 −1 𝑎−1 38 38

39 Proving an inequality Theorem 3: For all integers 𝑛≥4, 2𝑛<𝑛!
12/21/2017 Proving an inequality Theorem 3: For all integers 𝑛≥4, 2𝑛<𝑛! Rules for inequalities: Start from one side (say the left side) Work step by step towards the other. When dealing with <, you are allowed to make the expression larger, but never smaller. Example: if I am smaller than you, then I am still smaller than you when you stand on a bench. 39 39

40 2n = 2(2n-1) < 2(n-1)! < n(n-1)! = n!
12/21/2017 Theorem 3: ∀𝑛≥4, 2𝑛<𝑛! Another version of the induction step: We want to prove that ∀𝑛≥ ?, 2 𝑛−1 < 𝑛−1 !→ 2 𝑛 <𝑛!. Consider an unspecified n ≥ ?. Induction hypothesis: assume that 2n-1 < (n-1)! 2n = 2(2n-1) < 2(n-1)! < n(n-1)! = n! What is the smallest value of n that we should use in the induction step? less than 4 (d) 5 3 (e) more than 5 4 40 40

41 Sum of inverted squares
12/21/2017 Sum of inverted squares ∀𝑛≥1, 𝑖=1 𝑛 1 𝑖 2 ≤2− 1 𝑛 Theorem 4: An interesting mathematical fact (which doesn’t help with the proof): Let’s prove this! 𝑖=1 ∞ 1 𝑖 2 = π 2 6 41 41

42 Midterm 2 Work through the posted practice problem on converting a DFA to a sequential circuit! Topics covered: Converting a DFA to a sequential circuit Predicate logic to proof structure (assign #4 Q1) Proof structure to predicate logic (assign #4 Q2) Direct proof Proof by contrapositive and/or contradiction Induction

43 Theorem 4: ∀𝑛≥1, 𝑖=1 𝑛 1 𝑖 2 ≤2− 1 𝑛 After applying the induction hypothesis, what inequality do we need to prove? 2− 1 𝑛 + 1 (𝑛+1) 2 ≤2− 1 𝑛 Answer is (b). 2− 1 𝑛 + 1 (𝑛+1) 2 ≤2− 1 𝑛+1 2− 1 𝑛 (𝑛+1) 2 ≤2− 1 𝑛 2− 1 𝑛 (𝑛+1) 2 ≤2− 1 𝑛+1

44 A practice question for midterm 2
Prove the theorem by induction. You should be able to finish writing the proof structure (to the end of ”you need to show that”). Write your student ID and name clearly. I will collect these for participation marks.

45 Midterm 2 Work through the posted practice problem on converting a DFA to a sequential circuit! Topics covered: Converting a DFA to a sequential circuit Predicate logic to proof structure (assign #4 Q1) Proof structure to predicate logic (assign #4 Q2) Direct proof Proof by contrapositive and/or contradiction Induction

46 Sum of inverted squares
12/21/2017 Sum of inverted squares ∀𝑛≥1, 𝑖=1 𝑛 1 𝑖 2 ≤2− 1 𝑛 Theorem 4: An interesting mathematical fact (which doesn’t help with the proof): Let’s prove this! 𝑖=1 ∞ 1 𝑖 2 = π 2 6 46 46

47 Theorem 4: ∀𝑛≥1, 𝑖=1 𝑛 1 𝑖 2 ≤2− 1 𝑛 What should we prove in the base case? n = -1 n = 0 n = 1 n = 2 n = 3 Answer is (b).

48 Theorem 4: Both of a and b are correct.
∀𝑛≥1, 𝑖=1 𝑛 1 𝑖 2 ≤2− 1 𝑛 What do we need to prove in the induction step? Both of a and b are correct. Neither of a and b are correct. ∀𝑡∈𝑁, 𝑖=1 𝑛 1 𝑖 2 ≤2− 1 𝑛 → 𝑖=1 𝑛 𝑖 2 ≤2− 1 𝑛+1 ∀𝑡∈𝑁, 𝑖=1 𝑛 1 𝑖 2 ≤2− 1 𝑛 → ∀𝑡∈𝑁, 𝑖=1 𝑛 𝑖 2 ≤2− 1 𝑛+1 Theorem: P(0) ^ P(1) ^ P(2) ^ P(3) ^ … Option (a): P(0) -> P(1) ^ P(1) -> P(2) ^ P(2) -> P(3) ^ … Option (b): (P(0) ^ P(1) ^ P(2) ^ P(3) ^ …) -> (P(1) ^ P(2) ^ P(3) ^ P(4) ^ ...) This option says: if the equation is true for all natural numbers, then it is true for all positive integers. If we assume that the equation is true for all natural numbers, this is same as assuming that our theorem is true.

49 Proving a theorem about a DFA
12/21/2017 Proving a theorem about a DFA Consider the following DFA: 1 3 2 4 49 49

50 Which strings does this DFA accept?
12/21/2017 Which strings does this DFA accept? In addition to the empty string, what other strings does this DFA accept? Strings whose length is divisible by 5. Unsigned binary integers that are prime numbers. Strings with alternating 1’s and 0’s Unsigned binary integers that are divisible by 5. Counterexamples: (a) = 16. The string has 5 bits. We end up in state 1. (b) 3 = is prime. We end up in state 3. (c) We end up in state 1. Answer is (d) 50 50

51 Which strings does this DFA accept?
12/21/2017 Which strings does this DFA accept? In addition to the empty string, what other strings does this DFA accept? Strings whose length is divisible by 5. Unsigned binary integers that are prime numbers. Strings with alternating 1’s and 0’s Unsigned binary integers that are divisible by 5. Counterexamples: (a) = 16. The string has 5 bits. We end up in state 1. (b) 3 = is prime. We end up in state 3. (c) We end up in state 1. Answer is (d) 51 51

52 Proving a theorem about this DFA
12/21/2017 Proving a theorem about this DFA Suppose that we want to prove that this DFA only accepts binary numbers that are divisible by 5. Which statement should we prove (ignoring empty strings)? The DFA is in state 0 if and only if s is divisible by 5. The DFA is in state r if and only if r is the remainder when we divide s by 5. Answer is e. 52 52

53 Proving a theorem about this DFA
12/21/2017 Proving a theorem about this DFA Suppose that we want to prove that this DFA only accepts binary numbers that are divisible by 5. Which statement should we prove (ignoring empty strings)? The DFA is in state 0 if and only if s is divisible by 5. The DFA is in state r if and only if r is the remainder when we divide s by 5. We cannot prove a fact about state 0 without discussing the other states. Answer is e. 53 53

54 Proof: by induction on the length n of s.
12/21/2017 Theorem: The DFA ends up in state r after reading a string s if and only if ∃𝑞∈𝑍, 𝑠=5𝑞+𝑟. Proof: by induction on the length n of s. Base case: n = 1 This can be verified easily by looking at the DFA. Induction step: Consider an unspecified integer 𝑛≥2. Induction hypothesis: assume that the DFA behaves correctly for any string with n bits. We need to show that the DFA behaves correctly for any string with n + 1 bits. 54 54

55 12/21/2017 Theorem: The DFA ends up in state r after reading a string s if and only if ∃𝑞∈𝑍, 𝑠=5𝑞+𝑟. Proof (continued): Suppose that s = bn-1bn-2...b2b1b0. After reading the bits bn-1bn-2...b2b1, the DFA is in state r. By the induction hypothesis, the binary integer bn-1bn-2...b2b1 = 5q + r for some integer q. Now, s = 2 (bn-1bn-2...b2b1) + b0 = 2(5q+r) + b0 = 10q + 2r + b0 and so s = 5 (2q) + (2r + b0). So the DFA should have the following transitions: r b0 2r+b0 1 2 3 4 r b0 2r+b0 1 2 3 4 55 55

56 Corollary: the DFA is in state 0 if and only if s is divisible by 5.
12/21/2017 Theorem: The DFA ends up in state r after reading a string s if and only if ∃𝑞∈𝑍, 𝑠=5𝑞+𝑟. Proof (continued): It does, and hence after reading all n bits of s, the DFA ends up in state r if and only if ∃𝑞∈𝑍, 𝑠= 5𝑞+𝑟. Hence by the principle of mathematical induction, the DFA ends up in state r after reading a string s if and only if ∃𝑞∈𝑍, 𝑠=5𝑞+𝑟. QED Corollary: the DFA is in state 0 if and only if s is divisible by 5. 56 56

57 Induction is used to analyze recursive algorithms
12/21/2017 Induction is used to analyze recursive algorithms Example: (define (sum n) (if (= n 0) (+ n (sum (- n 1))))) The type of induction we discussed so far works when the recursive call is with (- n 1) 𝑖=0 𝑛 𝑖 =𝑛+ 𝑖=0 𝑛−1 𝑖 57 57

58 Module 9 outline Example: single-elimination tournaments.
12/21/2017 Module 9 outline Example: single-elimination tournaments. Defining and validating mathematical induction. More examples where we can use induction. A slightly different type of induction. 58 58

59 Handling general recursions
12/21/2017 Handling general recursions How do we handle more general recursions? A recursive function/method has One or more base cases When it can compute the answer directly An induction step It computes recursively the solutions to one or more “smaller” sub-problems, and combines them to obtain its answer. Our induction proofs mimic this structure. It is similar to the templates you used in CPSC 110. 59 59

60 A slightly different type of induction
12/21/2017 A slightly different type of induction We use a slightly different induction hypothesis. Instead of proving that ∀𝑛∈ 𝑍 + , 𝑃(𝑛)→𝑃(𝑛+1) We prove that ∀𝑛∈ 𝑍 + , 𝑃(1)∧𝑃(2)∧…∧𝑃(𝑛)→𝑃(𝑛+1) We can also show that this type of induction is a valid proof technique. The proof is the same proof by contradiction that we looked at earlier. 60 60

61 The induction we have seen so far
To solve n + 1, we make a recursive call to n (the previous case). Examples ( n-1 + 5n) + 5n+1 2n < n! ---> 2n+1 < (n+1)! The DFA behaves correctly for a string with n bits, then it also behaves correctly for a string with (n+1) bits. What if we need to make recursive call to one or more previous cases?

62 Carrying water across a desert
We need to buy jugs of water in order to cross a desert. Unfortunately, the water jugs only come in two sizes: 5 liters and 7 liters. Prove that as long as n >= 24, we can buy n liters of water using 5-liter and 7-liter jugs only.

63 The induction step/the recursive call
Which of the following ideas can be used for the induction step? If I can buy n-1 liters of water, then I can also buy n liters of water. If I can buy n-3 liters of water, then I can also buy n liters of water. If I can buy n-5 liters of water, then I can also buy n liters of water. If I can buy n-7 liters of water, then I can also buy n liters of water.

64 The induction step Version 1: P(n-5) -> P(n)
Suppose that we can buy (n-5) liters of water using x 5-liter jugs and y 7-liter jugs. Then we can buy n liters of water using (x+1) 5- liter jugs and y 7-liter jugs only. Version 2: P(n-7) -> P(n) Suppose that we can buy (n-7) liters of water using x 5-liter jugs and y 7-liter jugs. Then we can buy n liters of water using x 5-liter jugs and (y+1) 7-liter jugs only.

65 The base cases Induction step:
Assume that we can buy (n-5)L of water, then we can also buy nL of water. What is the smallest value of n for which we can apply the induction step? 24 25 28 29 30

66 The base cases Induction step:
Assume that we can buy (n-5)L of water, then we can also buy nL of water. How many base cases do we need to prove? 1 3 5 7 9

67 A lower bound for Fibonacci numbers
The Fibonacci numbers are defined as follows: F(0) = 0 F(1) = 1 F(n) = F(n-1) + F(n-2) for any n >= 2. Theorem: for every integer n >= 1, F(n) >= 1.6n-2.

68 The induction step/the recursive call
What should we prove in the induction step? If F(n-1) satisfies the theorem, then F(n) also satisfies the theorem. If F(n-2) satisfies the theorem, then F(n) also satisfies the theorem. If F(n-2) and F(n-1) satisfy the theorem, then F(n) also satisfies the theorem. If F(n) and F(n+1) satisfy the theorem, then F(n+2) also satisfies the theorem.

69 Let’s complete the induction step.

70 The base cases What is the smallest value of n for which we can apply the induction step? 1 2 3 4 What are the base cases that we need to prove?

71 Additional induction examples

72 12/21/2017 A binary tree A binary tree is a data structure that is defined recursively A binary tree is Empty, or A node with some data, and two children that are themselves trees. 10 5 20 We didn't draw the empty nodes in the figure. 2 9 15 7 17 72 72

73 Calculating the size of a binary tree
12/21/2017 Calculating the size of a binary tree Example 6: consider the following function: (define (tree-size t) (if (null? t) ( (tree-size (left-child t)) (tree-size (right-child t))))) Theorem 6: Prove that the above function correctly computes the number of (non-null) nodes of the tree. 73 73

74 Calculating the size of a binary tree
12/21/2017 Calculating the size of a binary tree Consider the following procedure to calculate the size of a binary tree. If the tree is null, then the size of the tree is 0. Otherwise, the size of the tree = 1 + the size of its left child + the size of its right child Theorem 6: Prove that the above procedure correctly computes the number of (non-null) nodes of the tree. 74 74

75 Calculating the size of a binary tree
12/21/2017 Calculating the size of a binary tree We prove this using mathematical induction on the size of the tree. Base case: t is null In this case t contains exactly 0 nodes. Induction step: Assume the algorithm works for trees that are smaller than t. Because the left sub-tree of t is smaller than t, the 1st recursive calls correctly returns the size of the left sub-tree of t. 75 75

76 Calculating the size of a binary tree
12/21/2017 Calculating the size of a binary tree Proof (continued) Induction step (continued) Similarly the right sub-tree of t is smaller than t, and so the 2nd recursive call correctly returns the size of the right sub-tree of t. But we return 1 + the sum of the values returned by the recursive calls. This is exactly the size of t (1 for the root, and the sum of the sizes of the two sub-trees). Hence by the principle of M.I., our algorithm computes correctly the size of every tree. QED 76 76

77 Randomized-quick-select
12/21/2017 Randomized-quick-select We can find the ith smallest element in an unsorted list as follows: Pick a random element x of the list. Divide the list into three sublists: list-smaller: elements smaller than x list-equal: elements equal to x list-larger: elements larger than x Then search list-smaller if i ≤ length of list-smaller list-larger if i > length of list smaller + length of list-equal otherwise return x 77 77

78 Randomized-quick-select
12/21/2017 Randomized-quick-select This algorithm is called randomized-quick-select. A student shows the expected number of steps S(n) of the algorithm on a list with n elements is: S(1) = 4c S(2) = 12c S(3) = 20c S(n) ≤ 2cn + S(Floor(3n/4)) when n ≥ 4 N = 4, Floor(3n/4) = S(4) <= 2cn + S(3) N = 5, Floor(15/4) = S(5) <= 2cn + S(3) N = 6, Floor(18/4) = S(6) <= 2cn + S(4) N = 7, Floor(21/4) = S(7) <= 2cn + S(5) N = 8, Floor(24/4) = S(8) <= 2cn + S(6) 78 78

79 Randomized-quick-select
12/21/2017 Randomized-quick-select Prove: for every n ≥ 1, S(n) ≤ 8cn. 79 79

80 Writing an integer as a product of primes
12/21/2017 Writing an integer as a product of primes Theorem 7: every positive integer n greater than 1 can be written as a product of primes. What base case(s) is/are the most appropriate? n = 1 n = 2 n = 2, 3 or 5. n is prime. None of the above. 80 80

81 Writing an integer as a product of primes
12/21/2017 Writing an integer as a product of primes Proof: we prove the result by induction on n. Base case: n We can write n = n and n is a product of primes (with only 1 prime). Induction step: n Suppose that every value from 2 to n – 1 is a product of primes. Since n We can write n = 81 81

82 Writing an integer as a product of primes
12/21/2017 Writing an integer as a product of primes Proof (continued) Since 2 ≤ a < n, Since 2 ≤ b < n, Then Hence by the principle of M.I., every positive integer larger than 1 can be written as a product of primes. QED (if (= x (vector-ref avector first-pos)) first-pos #f) mid-pos (find-element avector first-pos (- mid-pos 1) x) (find-element avector (+ mid-pos 1) last-pos x) 82 82

83 The binary search algorithm
12/21/2017 The binary search algorithm Example 9: binary search Suppose we have something like a list, but whose ith element and length can be found in a single step. This structure is called a vector in Racket. It is similar to an ArrayList in Java. We assume that we have such a vector, sorted in increasing order. Examples: (“Anh”, “Charles”, “Dora”, “Gregor”, “Wei”). We want to find the position of a given element (for instance, “Dora”). 83 83

84 The binary search algorithm
12/21/2017 The binary search algorithm The following algorithm (formerly known as B) works: (define (binary-search avector first-pos last-pos x) (if (> first-pos last-pos) false (if (= first-pos last-pos) (if (= (vector-ref avector first-pos) x) first-pos false) (local ((define mid-pos (quotient (+ first-pos last-pos) 2))) (if (= x (vector-ref avector mid-pos)) mid-pos (if (< x (vector-ref avector mid-pos)) (binary-search avector first-pos (- mid-pos 1) x) (binary-search avector (+ mid-pos 1) last-pos x))))))) 84 84

85 The binary search algorithm
12/21/2017 The binary search algorithm Prove that binary search makes at most ⌈log2 (size+1)⌉ comparisons if size ≥ 1. The proof is once again by induction on size. Base case: size = The algorithm uses comparison, which is Induction step: Consider an unspecified size . Assume that # comps = 1 + # comps for ceil((size – 1)/2) = 1 + ceil (log (ceil((size – 1)/2 + 1))) = 1 + ceil (log (ceil((size + 1)/2))) = ceil(1 + log (ceil((size + 1)/2))) = ceil(log (2 * ceil((size + 1)/2))) Now if size is even, then this is ceil (log (size + 2)), which is the same as ceil (log (size + 1)). And if size is odd, then this is ceil (log (size + 1)). 85 85


Download ppt "Module 9: Mathematical Induction"

Similar presentations


Ads by Google