1 Recursion, Recurrences and Induction Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.

Slides:



Advertisements
Similar presentations
Week 5 - Friday.  What did we talk about last time?  Sequences  Summation and production notation  Proof by induction.
Advertisements

1 Mathematical Induction. 2 Mathematical Induction: Example  Show that any postage of ≥ 8¢ can be obtained using 3¢ and 5¢ stamps.  First check for.
1 The RSA Algorithm Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.
CSE115/ENGR160 Discrete Mathematics 04/19/12 Ming-Hsuan Yang UC Merced 1.
Tirgul 2 Asymptotic Analysis. Motivation: Suppose you want to evaluate two programs according to their run-time for inputs of size n. The first has run-time.
1 Quantifiers Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.
Discrete Structures Chapter 6 Recurrence Relations
Recursive Definitions Rosen, 3.4. Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
1 Intro to Induction Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.
Inverses and GCDs Supplementary Notes Prepared by Raymond Wong
1 Inference Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.
1 Mathematical Induction. 2 Mathematical Induction: Example  Show that any postage of ≥ 8¢ can be obtained using 3¢ and 5¢ stamps.  First check for.
1 Solutions to Recurrences Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.
Tirgul 2 Asymptotic Analysis. Motivation: Suppose you want to evaluate two programs according to their run-time for inputs of size n. The first has run-time.
Discrete Structures Chapter 5: Sequences, Mathematical Induction, and Recursion 5.2 Mathematical Induction I [Mathematical induction is] the standard proof.
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
1 Section 3.3 Mathematical Induction. 2 Technique used extensively to prove results about large variety of discrete objects Can only be used to prove.
1 Advanced Induction Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.
Properties of the Integers: Mathematical Induction
1 Mathematical Induction. 2 Mathematical Induction: Example  Show that any postage of ≥ 8¢ can be obtained using 3¢ and 5¢ stamps.  First check for.
Copyright © 2007 Pearson Education, Inc. Slide 8-1.
Analysis of Recursive Algorithms October 29, 2014
Advanced Counting Techniques
Sequences and Series (T) Students will know the form of an Arithmetic sequence.  Arithmetic Sequence: There exists a common difference (d) between each.
Lecture 9. Arithmetic and geometric series and mathematical induction
RMIT University; Taylor's College1 Lecture 6  To apply the Principle of Mathematical Induction  To solve the Towers of Hanoi puzzle  To define a recurrence.
Chapter 6 Mathematical Induction
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Mathematical Induction. F(1) = 1; F(n+1) = F(n) + (2n+1) for n≥ F(n) n F(n) =n 2 for all n ≥ 1 Prove it!
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
INDUCTION AND RECURSION. PRINCIPLE OF MATHEMATICAL INDUCTION To prove that P(n) is true for all positive integers n, where P(n) is a propositional function,
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Recurrence Relation. Outline  What is a recurrence relation ?  Solving linear recurrence relations  Divide-and-conquer algorithms and recurrence relations.
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2.5 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
RECURRENCE Sequence Recursively defined sequence
Foundations of Discrete Mathematics Chapters 5 By Dr. Dalia M. Gil, Ph.D.
Sequences and Summations
Complexity A decidable problem is computationally solvable. But what resources are needed to solve the problem? –How much time will it require? –How much.
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
1 Put your name if you want your attendance credit. Please put your as well. CSC 320 is done at 11:30 so I did NOT fill in the box for 11:30 for.
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Sequences and Summations Section 2.4. Section Summary Sequences. – Examples: Geometric Progression, Arithmetic Progression Recurrence Relations – Example:
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
Foundations of Discrete Mathematics Chapters 5 By Dr. Dalia M. Gil, Ph.D.
Solving Recurrence Relations by Iteration Lecture 36 Section 8.2 Mon, Apr 17, 2006.
Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.
COMP 170 L2 L11: Recursion, Recurrence, and Induction l Objective n Recursion  A problem solving technique that reduces big problems into smaller ones.
RECURRENCE Sequence Recursively defined sequence
Recursion and Induction Themes –Recursion –Recurrence Definitions –Recursive Relations –Induction (prove properties of recursive programs and objects defined.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
Mathematical Induction Thinking Skill: Develop Confidence in Reason Warm Up: Find the k+1 term (P k+1 ) 1) 2)
Sequences and the Binomial Theorem Sequences Arithmetic Sequences Geometric Sequences & Series Binomial Theorem.
1 RECURRENCE 1. Sequence 2. Recursively defined sequence 3. Finding an explicit formula for recurrence relation.
1 Discrete Mathematical Mathematical Induction ( الاستقراء الرياضي )
Mathematical Analysis of Recursive Algorithm CSG3F3 Lecture 7.
Mathematical Induction And Recursion Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
1 Lecture Outline for Recurrences Already Covered: Recursive definition of sequences Recursive definition of sets Recursive definition of operations Recursive.
Fall 2002CMSC Discrete Structures1 Chapter 3 Sequences Mathematical Induction Recursion Recursion.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
Proofs, Recursion and Analysis of Algorithms
Mathematical Induction Recursion
Notes 9.5 – Mathematical Induction
Section 2.1 Proof Techniques Introduce proof techniques:   o        Exhaustive Proof: to prove all possible cases, Only if it is about a.
Copyright © Cengage Learning. All rights reserved.
Applied Discrete Mathematics Week 9: Integer Properties
Solving Recurrence Relations by Iteration
Chapter 11: Further Topics in Algebra
Copyright © Cengage Learning. All rights reserved.
Mathematical Induction
Presentation transcript:

1 Recursion, Recurrences and Induction Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong

2 e.g.1 (Page 7) Tower of Hanoi When n = 1 (i.e., no. of disks = 1) I want to move all n disks from i to j i j{i, j}

3 e.g.1 Tower of Hanoi When n = 1 (i.e., no. of disks = 1) I want to move all n disks from i to j i j{i, j} We move ONE disk from i to j. No. of disk moves = 1 Disk move:Moving ONE disk from i to j

4 e.g.1 Tower of Hanoi When n = 2 (i.e., no. of disks = 2) I want to move all n disks from i to j i j{i, j} Top disk Bottom disk

5 e.g.1 Tower of Hanoi When n = 2 (i.e., no. of disks = 2) I want to move all n disks from i to j i j{i, j}

6 e.g.1 Tower of Hanoi When n = 2 (i.e., no. of disks = 2) I want to move all n disks from i to j i j{i, j} We move ONE top disk from i to {i, j}. No. of disk moves = 1 Disk move: Moving ONE top disk from i to {i, j}

7 e.g.1 Tower of Hanoi When n = 2 (i.e., no. of disks = 2) I want to move all n disks from i to j i j{i, j} We move ONE bottom disk from i to j. No. of disk moves = 1 Disk move: Moving ONE top disk from i to {i, j} Moving ONE bottom disk from i to j 2

8 e.g.1 Tower of Hanoi When n = 2 (i.e., no. of disks = 2) I want to move all n disks from i to j i j{i, j} We move ONE top disk from {i, j} to j. No. of disk moves = 1 Disk move: Moving ONE top disk from i to {i, j} Moving ONE bottom disk from i to j 2 Moving ONE top disk from {i, j} to j 3

9 e.g.1 Tower of Hanoi n can be any positive integer I want to move all n disks from i to j i j{i, j} Top disk group containing n-1 disks Bottom disk Virtual top box

10 e.g.1 Tower of Hanoi n can be any positive integer I want to move all n disks from i to j i j{i, j}

11 e.g.1 Tower of Hanoi n can be any positive integer I want to move all n disks from i to j i j{i, j} We move ONE top disk group from i to {i, j}. No. of disk moves = no. of disk moves for one top disk group Disk move: Moving ONE top disk group from i to {i, j}

12 e.g.1 Tower of Hanoi n can be any positive integer I want to move all n disks from i to j i j{i, j} We move ONE bottom disk from i to j. No. of disk moves = no. of disk moves for one top disk group Disk move: Moving ONE top disk group from i to {i, j} Moving ONE bottom disk from i to j + 1

13 e.g.1 Tower of Hanoi n can be any positive integer I want to move all n disks from i to j i j{i, j} Disk move: Moving ONE top disk group from i to {i, j} Moving ONE bottom disk from i to j We move ONE top disk group from {i, j} to j.Moving ONE top disk group from {i, j} to j No. of disk moves = no. of disk moves for one top disk group no. of disk moves for one top disk group

14 e.g.1 Tower of Hanoi n can be any positive integer I want to move all n disks from i to j i j{i, j} Disk move: Moving ONE top disk group from i to {i, j} Moving ONE bottom disk from i to j We move ONE top disk group from {i, j} to j. Moving ONE top disk group from {i, j} to j No. of disk moves = 2. no. of disk moves for one top disk group + 1 No. of disk moves for n disks No. of disk moves for n-1 disks

15 e.g.1 Tower of Hanoi n can be any positive integer I want to move all n disks from i to j Disk move: Moving ONE top disk group from i to {i, j} Moving ONE bottom disk from i to j Moving ONE top disk group from {i, j} to j No. of disk moves = 2. no. of disk moves for one top disk group + 1 No. of disk moves for n disks No. of disk moves for n-1 disks The top disk group corresponds to top n-1 disks top n-1 disks The bottom disk corresponds to the largest disk the largest disk Let M(n) be the total number of disk moves needed for n disks. M(n)M(n-1) Note that M(1) = 1

16 e.g.1 Tower of Hanoi n can be any positive integer I want to move all n disks from i to j Disk move: Moving ONE top disk group from i to {i, j} Moving ONE bottom disk from i to j Moving ONE top disk group from {i, j} to j No. of disk moves = 2. no. of disk moves for one top disk group + 1 No. of disk moves for n disks top n-1 disks the largest disk M(n)M(n-1) Why is it correct? This is because we are implicitly using induction. We assume that we can move top n-1 disks correctly. Let p(n) is a statement that the algorithm is correct for n. Step 1: Prove that p(1) (i.e., the base case) is true. Step 2: Prove that “ p(n-1)  p(n) ” is true for all n > 1. Step 2(a): Assume that p(n-1) is true for n > 1. Verify that p(1) is true Step 2(b): According to p(n-1), we deduce that p(n) is true. Inductive Hypothesis Inductive Step Note that M(1) = 1

17 e.g.1 Tower of Hanoi n can be any positive integer I want to move all n disks from i to j Disk move: Moving ONE top disk group from i to {i, j} Moving ONE bottom disk from i to j Moving ONE top disk group from {i, j} to j No. of disk moves = 2. no. of disk moves for one top disk group + 1 No. of disk moves for n disks top n-1 disks the largest disk M(n)M(n-1) Why is it correct? This is because we are implicitly using induction. We assume that we can move top n-1 disks correctly. Let p(n) is a statement that the algorithm is correct for n. Step 1: Prove that p(1) (i.e., the base case) is true. Note that M(1) = 1

18 e.g.1 Tower of Hanoi When n = 1 (i.e., no. of disks = 1) I want to move all n disks from i to j i j{i, j} Step 1: Prove that p(1) (i.e., the base case) is true.

19 e.g.1 Tower of Hanoi When n = 1 (i.e., no. of disks = 1) I want to move all n disks from i to j i j{i, j} This case is obviously true. Step 1: Prove that p(1) (i.e., the base case) is true.

20 e.g.1 Tower of Hanoi n can be any positive integer I want to move all n disks from i to j i j{i, j} Step 2: Prove that “ p(n-1)  p(n) ” is true for all n > 1. Step 2(a): Assume that p(n-1) is true for n > 1. Step 2(b): According to p(n-1), we deduce that p(n) is true.

21 e.g.1 Tower of Hanoi n can be any positive integer I want to move all n disks from i to j i j{i, j} We move ONE top disk group from i to {i, j}. Step 2: Prove that “ p(n-1)  p(n) ” is true for all n > 1. Step 2(a): Assume that p(n-1) is true for n > 1. Step 2(b): According to p(n-1), we deduce that p(n) is true. We assume that moving n-1 disks is correct.

22 e.g.1 Tower of Hanoi n can be any positive integer I want to move all n disks from i to j i j{i, j} We move ONE bottom disk from i to j. Step 2: Prove that “ p(n-1)  p(n) ” is true for all n > 1. Step 2(a): Assume that p(n-1) is true for n > 1. Step 2(b): According to p(n-1), we deduce that p(n) is true.

23 e.g.1 Tower of Hanoi n can be any positive integer I want to move all n disks from i to j i j{i, j} We move ONE top disk group from {i, j} to j. Step 2: Prove that “ p(n-1)  p(n) ” is true for all n > 1. Step 2(a): Assume that p(n-1) is true for n > 1. Step 2(b): According to p(n-1), we deduce that p(n) is true. We assume that moving n-1 disks is correct.

24 e.g.2 (Page 11) Given M(1) = 1 and M(n) = 2M(n-1) + 1 for n > 1 What are the values of M(1), M(2), M(3), M(4) and M(5)? M(1) =1 M(2) =2M(1) + 1= = 3 M(3) =2M(2) + 1= = 7 M(4) =2M(3) + 1= = 15 M(5) =2M(4) + 1= = It “ seems ” that M(n) = 2 n -1

25 e.g.3 (Page 12) Illustration of “Proof by mathematical induction” (Weak Induction) We are going to prove the following claim C: statement P(n) is true for each positive integer n, namely 1, 2, … P(1)true P(2) P(3) P(4) P(5) … Step 1: Prove that P(1) (i.e., the base case) is true. Step 2: Prove that “ P(n-1)  P(n) ” is true for all n > 1. true Step 2(a): Assume that P(n-1) is true for n > 1. Verify that P(1) is true Step 2(b): According to P(n-1), we deduce that P(n) is true. Inductive Hypothesis Inductive Step

26 e.g.4 (Page 17) Let S(n) be the number of subsets of a set X of size n. What are the values of S(0), S(1), S(2) and S(3)? When n = 0,X = {}There is a subset, namely an empty set (i.e., {}) When n = 1,X = {1}There are 2 subsets, namely {} and {1}. Thus, S(0) = 1 Thus, S(1) = 2 When n = 2,X = {1, 2}There are 4 subsets, namely {}, {1}, {2}, {1, 2}. Thus, S(2) = 4 When n = 3,X = {1, 2, 3}There are 8 subsets, namely {},{1},{2},{3},{1, 2},{1, 3},{2, 3},{1, 2, 3} Thus, S(3) = 8 It “ seems ” that S(n) = 2 n

27 e.g.4 Consider the 8 subsets of {1, 2, 3} {}{1}{2}{1, 2} {3}{3}{1, 3}{2, 3}{1, 2, 3} All 4 possible subsets of {1, 2} Each set is the same as the above set by adding a number 3 All possible subsets of a set of size 2. The total number of such subsets is equal to S(2). All possible subsets of a set of size 2 by adding a number 3 The total number of such subsets is equal to S(2). The total number of subsets of a set of size 3 (i.e., S(3) ) is equal to2. S(2) In general, we derive that S(n) = 2. S(n-1) We want to find a recursion formula for S(n).

28 e.g.5 (Page 21) time 0123 n-1n … Raymond borrows a loan with initial amount A (e.g., $100,000) from the bank. Raymond needs to return a monthly payment M (e.g., $1000) every month. Raymond returns a monthly payment M (e.g., $1000) to the bank. Raymond returns M Suppose T(n) is the amount of money in the bank at the n-th month. T(0)T(1)T(2)T(3)T(n-1)T(n)

29 e.g.5 time 0123 n-1n … Raymond borrows a loan with initial amount A (e.g., $100,000) from the bank. Raymond needs to return a monthly payment M (e.g., $1000) every month. Raymond returns a monthly payment M (e.g., $1000) to the bank. Raymond returns M Suppose T(n) is the amount of money in the bank at the n-th month. T(0)T(1)T(2)T(3)T(n-1)T(n) =A =T(0)*(1+0.01p/12) – M Suppose the interest rate is p% per year Suppose the interest rate is (p/12)% per month. Suppose the interest rate is (0.01p/12) per month. =T(1)*(1+0.01p/12) – M =T(n-1)*(1+0.01p/12) – M …

30 e.g.6 (Page 24) T(0) = b T(n) = rT(n-1) + a if n > 0 Derive a closed form for T(n) by a “ top-down ” approach (or called iterating recurrence) T(0) = b T(n) = rT(n-1) + a if n > 0

31 e.g.6 T(0) = b T(n) = rT(n-1) + a if n > 0 T(n) = rT(n-1) + a = r(rT(n-2) + a) + a = r 2 T(n-2) + ra + a = r 2 (rT(n-3) + a) + ra + a = r 3 T(n-3) + r 2 a + ra + a = r 3 (rT(n-4) + a) + r 2 a + ra + a = r 4 T(n-4) + r 3 a + r 2 a + ra + a = … = r n T(n-n) + r n-1 a + r n-2 a + … + ra + a = r n T(0) + a(r n-1 + r n-2 + … + r + 1) = r n T(0) + a(r n-1 + r n-2 + … + r + r 0 ) = r n b + a  r i Note that  r i = 1 – r n 1 – r if r  1 = r n b + a 1 – r n 1 – r

32 e.g.7 (Page 25) T(0) = b T(n) = rT(n-1) + a if n > 0 Derive a closed form for T(n) by a “ bottom-up ” approach T(0) = b T(n) = rT(n-1) + a if n > 0

33 e.g.6 T(0) = b T(n) = rT(n-1) + a if n > 0 T(0) = b T(1) = rT(0) + a= rb + a T(2) = rT(1) + a= r(rb+a) + a= r 2 b + ra + a T(3) = rT(2) + a= r(r 2 b + ra + a) + a= r 3 b + r 2 a+ ra + a … T(n) = r n b + r n-1 a + r n-2 a + … + ra + a = r n b + a(r n-1 + r n-2 + … + r + 1) = r n b + a(r n-1 + r n-2 + … + r + r 0 ) = r n b + a  r i Note that  r i = 1 – r n 1 – r if r  1 = r n b + a 1 – r n 1 – r

34 e.g.7 (Page 31) We want to prove the following corollary. Corollary 4.2: The formula for the sum of a geometric series with r  1 is  r i = 1 – r n 1 – r

35 e.g.7 Corollary 4.2: The formula for the sum of a geometric series with r  1 is  r i = 1 – r n 1 – r Theorem 4.1 is shown as follows. Theorem 4.1: If T(0) = b T(n) = rT(n-1) + a if n > 0 then = r n b + a 1 – r n 1 – r T(n) Let T(0) = 0 Let T(n) =  r i for n > 0 We want to show that T(n) = 1 – r n 1 – r by using Theorem 4.1 (which is related to recursion). We want to write T(n) in a recursion form. Consider T(n) = r n-1 + r n-2 + … + r + r 0 = (r n-1 + r n-2 + … + r) + r 0 = r(r n-2 + r n-3 + … + r 0 ) + 1 = r T(n-1) + 1 This is in a recursion form. We know that b = 0 We know that a = 1 According to Theorem 4.1, we have = r n b + a 1 – r n 1 – r T(n) = r n – r n 1 – r 1 – r n 1 – r = Done

36 e.g.8 (Page 32) We want to prove the following theorem. Lemma 4.3: Let r  1 be a positive value independent of n. Let t(n) be the largest term in the geometric series Then, the value of the geometric series is O(t(n)).  r i e.g.,If r = 0.5, then we have the value V of geometric series is equal to … n … n-1 The largest term t(n) in this series is equal to1 (= ) e.g.,If r = 2, then we have the value V of geometric series is equal to … + 2 n … + 2 n-1 The largest term t(n) in this series is equal to2 n-1 Lemma 4.3 states that V = O(t(n)) = O(1) Lemma 4.3 states that V = O(t(n)) = O(2 n-1 ) Why is it correct?

37 e.g.8 Lemma 4.3: Let r  1 be a positive value independent of n. Let t(n) be the largest term in the geometric series Then, the value of the geometric series is O(t(n)).  r i Consider two case. Case 1: r < 1 Case 2: r > 1 From our previous slide, we know that t(n) = r 0 = 1 From our previous slide, we know that t(n) = r n-1 Consider Case 1  r i We know that = 1 – r n 1 – r < 1 Note that r is a constant. 1 1 – r Thus, is a constant. = O(1) = O(t(n)) Note that we can show that =  (t(n))  r i

38 e.g.8 Lemma 4.3: Let r  1 be a positive value independent of n. Let t(n) be the largest term in the geometric series Then, the value of the geometric series is O(t(n)).  r i Consider two case. Case 1: r < 1 Case 2: r > 1 From our previous slide, we know that t(n) = r 0 = 1 From our previous slide, we know that t(n) = r n-1 Consider Case 2  r i We know that = 1 – r n 1 – r Note that r is a constant. r 1 – r Thus, is a constant. = O(r n-1 ) = O(t(n)) = r n – 1 r – 1 < r n r – 1 = r r n-1 Note that we can show that =  (t(n))  r i

39 e.g.9 (Page 35) First-order Linear Recurrence Dependent on one-step backward (i.e., T(n-1)) E.g., T(n) = f(n)T(n-1) + g(n) Second-order Linear Recurrence Dependent on two-steps backward (i.e., T(n-2)) E.g., T(n) = T(n-1) +2T(n-2) First-order Non-Linear Recurrence Linear means the power of T(n-1) is 1. Non-linear means the power of T(n-1) is not 1. E.g., T(n) = (T(n-1)) We are interested in this recurrence where f(n) is equal to a constant r.

40 e.g.10 (Page 37) Prove the following Theorem 4.5 by induction. Theorem 4.5: For any positive constants a and r, and any function g defined on the non-negative integers, the solution to the first-order linear recurrence is T(n) = rT(n-1) + g(n) if n > 0, a if n = 0,  r n-i T(n) = r n a + g(i) (*)

41 e.g.10 Theorem 4.5: For any positive constants a and r, and any function g defined on the non-negative integers, the solution to the first-order linear recurrence is T(n) = rT(n-1) + g(n) if n > 0, a if n = 0,  r n-i T(n) = r n a + g(i) (*) Step 1: Prove that P(0) (i.e., the base case) is true. Let P(n) be “ ”  r n-i T(n) = r n a + g(i) T(0) = a (by definition) = r 0 a We want to show that  r 0-i T(0) = r 0 a + g(i) That is, T(0) = r 0 a Thus, P(0) is true.

42 e.g.10 Theorem 4.5: For any positive constants a and r, and any function g defined on the non-negative integers, the solution to the first-order linear recurrence is T(n) = rT(n-1) + g(n) if n > 0, a if n = 0,  r n-i T(n) = r n a + g(i) (*) Let P(n) be “ ”  r n-i T(n) = r n a + g(i) Step 2: Prove that “ P(n-1)  P(n) ” is true for all n > 0. Step 2(a): Assume that P(n-1) is true for n > 0.  r (n-1)-i T(n-1) = r n-1 a + g(i) That is, Step 2(b): According to P(n-1), we deduce that P(n) is true. Consider T(n)= rT(n-1) + g(n) (by definition)  r (n-1)-i r n-1 a + g(i) = r( ) + g(n) We want to show that  r n-i T(n) = r n a + g(i)  r (n-1)-i r n a + r g(i) = + g(n)  r 1+(n-1)-i r n a + g(i) = + g(n)  r n-i r n a + g(i) = + r n-n g(n)  r n-i r n a + g(i) =

43 e.g.10 Theorem 4.5: For any positive constants a and r, and any function g defined on the non-negative integers, the solution to the first-order linear recurrence is T(n) = rT(n-1) + g(n) if n > 0, a if n = 0,  r n-i T(n) = r n a + g(i) (*) Let P(n) be “ ”  r n-i T(n) = r n a + g(i) Step 2: Prove that “ P(n-1)  P(n) ” is true for all n > 0. Step 2(a): Assume that P(n-1) is true for n > 0.  r (n-1)--i T(n-1) = r n-1 a + g(i) That is, Step 2(b): According to P(n-1), we deduce that P(n) is true. We want to show that  r n-i T(n) = r n a + g(i) Thus, P(n) is true. We prove that “ P(n-1)  P(n) ” is true for all n > 0 By Mathematical Induction,  r n-i T(n) = r n a + g(i)

44 e.g.11 (Page 39) We want to find the closed form of T(n) where T(0) = 6 T(n) = 4T(n-1) + 2 n if n > 0 T(0) = 6 T(n) = 4T(n-1) + 2 n if n > 0

45 e.g.11 T(0) = 6 T(n) = 4T(n-1) + 2 n if n > 0 Theorem 4.5: For any positive constants a and r, and any function g defined on the non-negative integers, the solution to the first-order linear recurrence is T(n) = rT(n-1) + g(n) if n > 0, a if n = 0,  r n-i T(n) = r n a + g(i) (*) We can write the closed form directly by using Theorem 4.5. We haver = 4g(n) = 2 n a= 6 Thus, by using Theorem 4.5, we have  r n-i T(n) = r n a + g(i) = 4 n n-i. 2 i = 4 n n 4 -i. 2 i

46 e.g.11 T(0) = 6 T(n) = 4T(n-1) + 2 n if n > 0 We can write the closed form directly by using Theorem 4.5. We haver = 4g(n) = 2 n a= 6 Thus, by using Theorem 4.5, we have  r n-i T(n) = r n a + g(i) = 4 n n-i. 2 i = 4 n n 4 -i. 2 i = 4 n n (2 2 ) -i. 2 i = 4 n n 2 -2i. 2 i = 4 n n 2 -i = 4 n n 1 2 ( ) i = 4 n n 1 2 ( ) i = 4 n n 1 2 ( ) i 1 2 = 4 n n – ( ½ ) n 1 – ½ = 4 n n – ( ½ ) n ½ = 4 n n. (1 – ( ½ ) n ) = 4 n n – 4 n ( ½ ) n = 4 n. 7 – 2 2n. 2 -n = 4 n. 7 – 2 n

47 e.g.12 (Page 40) We want to find the closed form of T(n) where T(0) = 10 T(n) = 3T(n-1) + n if n > 0 T(0) = 10 T(n) = 3T(n-1) + n if n > 0

48 e.g.12 T(0) = 10 T(n) = 3T(n-1) + n if n > 0 Theorem 4.5: For any positive constants a and r, and any function g defined on the non-negative integers, the solution to the first-order linear recurrence is T(n) = rT(n-1) + g(n) if n > 0, a if n = 0,  r n-i T(n) = r n a + g(i) (*) We can write the closed form directly by using Theorem 4.5. We haver = 3g(n) = na= 10 Thus, by using Theorem 4.5, we have  r n-i T(n) = r n a + g(i) = 3 n n-i. i= 3 n n 3 -i. i= 3 n n i. 3 -i

49 e.g.12 T(0) = 10 T(n) = 3T(n-1) + n if n > 0 We can write the closed form directly by using Theorem 4.5. We haver = 3g(n) = na= 10 Thus, by using Theorem 4.5, we have  r n-i T(n) = r n a + g(i) = 3 n n-i. i= 3 n n 3 -i. i= 3 n n i. 3 -i Theorem 4.6: For any real number x  1, i. x i = nx n+2 – (n+1)x n+1 + x (1-x) 2 Suppose that we know the following theorem. i. 3 -i =i. (1/3) i n(1/3) n+2 – (n+1)(1/3) n+1 + (1/3) (1-1/3) 2 = n. 3 -(n+2) – (n+1)3 -(n+1) (2/3) 2 =. (n. 3 -(n+2) – (n+1)3 -(n+1) ) = 32322

50 e.g.12 T(0) = 10 T(n) = 3T(n-1) + n if n > 0 We can write the closed form directly by using Theorem 4.5. We haver = 3g(n) = na= 10 Thus, by using Theorem 4.5, we have  r n-i T(n) = r n a + g(i) = 3 n n-i. i= 3 n n 3 -i. i= 3 n n i. 3 -i Theorem 4.6: For any real number x  1, i. x i = nx n+2 – (n+1)x n+1 + x (1-x) 2 Suppose that we know the following theorem. i. 3 -i. (n. 3 -(n+2) – (n+1)3 -(n+1) ) = (n. 3 -(n+2)+2 – (n+1)3 -(n+1) ) = 12. (n. 3 -n – (n+1)3 -n ) = 1 4. (n. 3 -n – (n+1)3. 3 -n + 3) = 1 4

51 e.g.12 T(0) = 10 T(n) = 3T(n-1) + n if n > 0 We can write the closed form directly by using Theorem 4.5. We haver = 3g(n) = na= 10 Thus, by using Theorem 4.5, we have  r n-i T(n) = r n a + g(i) = 3 n n-i. i= 3 n n 3 -i. i= 3 n n i. 3 -i Theorem 4.6: For any real number x  1, i. x i = nx n+2 – (n+1)x n+1 + x (1-x) 2 Suppose that we know the following theorem. i. 3 -i. (n. 3 -n – (n+1)3. 3 -n + 3) = 1 4. (n. 3 -n – (3n+3). 3 -n + 3) = 1 4. (n. 3 -n – 3n. 3 -n – n + 3) = 1 4. ( – 2n. 3 -n – n + 3) = 1 4

52 e.g.12 T(0) = 10 T(n) = 3T(n-1) + n if n > 0 We can write the closed form directly by using Theorem 4.5. We haver = 3g(n) = na= 10 Thus, by using Theorem 4.5, we have  r n-i T(n) = r n a + g(i) = 3 n n-i. i= 3 n n 3 -i. i= 3 n n i. 3 -i Theorem 4.6: For any real number x  1, i. x i = nx n+2 – (n+1)x n+1 + x (1-x) 2 Suppose that we know the following theorem. i. 3 -i. ( – 2n. 3 -n – n + 3) = 1 4. [( – 2n – 3). 3 -n + 3] = 1 4 = – 2n – n i. 3 -i = – 2n – n + 3 4

53 e.g.12 T(0) = 10 T(n) = 3T(n-1) + n if n > 0 We can write the closed form directly by using Theorem 4.5. We haver = 3g(n) = na= 10 Thus, by using Theorem 4.5, we have  r n-i T(n) = r n a + g(i) = 3 n n-i. i= 3 n n 3 -i. i= 3 n n i. 3 -i Suppose that we know the following theorem. i. 3 -i = – 2n – n = 3 n n ( – 2n – n ) = 3 n – 2n – n. 3 4 = 3 n. (10 + ) – 2n = 3 n. – 2n