Download presentation

Presentation is loading. Please wait.

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

2
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
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
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
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
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
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
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
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
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
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
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
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 + 1 + no. of disk moves for one top disk group

14
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
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
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
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
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
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
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
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
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
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
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= 2. 1 + 1 = 3 M(3) =2M(2) + 1= 2. 3 + 1 = 7 M(4) =2M(3) + 1= 2. 7 + 1 = 15 M(5) =2M(4) + 1= 2. 15 + 1 = 31 2 1 - 1 2 2 - 1 2 3 - 1 2 4 - 1 2 5 - 1 It “ seems ” that M(n) = 2 n -1

25
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
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 2020 2121 2 2323

27
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
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
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
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
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
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
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
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
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 0 + 1 1 – r n 1 – r 1 – r n 1 – r = Done

36
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 0.5 0 + 0.5 1 + 0.5 2 + … + 0.5 n-1 1 + 0.5 + 0.25 + … + 0.5 n-1 The largest term t(n) in this series is equal to1 (= 0.5 0 ) e.g.,If r = 2, then we have the value V of geometric series is equal to 2 0 + 2 1 + 2 2 + … + 2 n-1 1 + 2+ 2 + … + 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
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
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
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)) 2 + 3 We are interested in this recurrence where f(n) is equal to a constant r.

40
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
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
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
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
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
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. 6 + 4 n-i. 2 i = 4 n. 6 +4 n 4 -i. 2 i

46
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. 6 + 4 n-i. 2 i = 4 n. 6 +4 n 4 -i. 2 i = 4 n. 6 +4 n (2 2 ) -i. 2 i = 4 n. 6 +4 n 2 -2i. 2 i = 4 n. 6 +4 n 2 -i = 4 n. 6 +4 n 1 2 ( ) i = 4 n. 6 +4 n 1 2 ( ) i-1 1 2 = 4 n. 6 +4 n 1 2 ( ) i 1 2 = 4 n. 6 +4 n. 1 2 1 – ( ½ ) n 1 – ½ = 4 n. 6 +4 n. 1 2 1 – ( ½ ) n ½ = 4 n. 6 +4 n. (1 – ( ½ ) n ) = 4 n. 6 +4 n – 4 n ( ½ ) n = 4 n. 7 – 2 2n. 2 -n = 4 n. 7 – 2 n

47
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
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. 10 + 3 n-i. i= 3 n. 10 + 3 n 3 -i. i= 3 n. 10 + 3 n i. 3 -i

49
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. 10 + 3 n-i. i= 3 n. 10 + 3 n 3 -i. i= 3 n. 10 + 3 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) + 3 -1 (2/3) 2 =. (n. 3 -(n+2) – (n+1)3 -(n+1) + 3 -1 ) = 32322

50
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. 10 + 3 n-i. i= 3 n. 10 + 3 n 3 -i. i= 3 n. 10 + 3 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) + 3 -1 ) = 32322. (n. 3 -(n+2)+2 – (n+1)3 -(n+1)+2 + 3 -1+2 ) = 12. (n. 3 -n – (n+1)3 -n+1 + 3 1 ) = 1 4. (n. 3 -n – (n+1)3. 3 -n + 3) = 1 4

51
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. 10 + 3 n-i. i= 3 n. 10 + 3 n 3 -i. i= 3 n. 10 + 3 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 – 3. 3 -n + 3) = 1 4. ( – 2n. 3 -n – 3. 3 -n + 3) = 1 4

52
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. 10 + 3 n-i. i= 3 n. 10 + 3 n 3 -i. i= 3 n. 10 + 3 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 – 3. 3 -n + 3) = 1 4. [( – 2n – 3). 3 -n + 3] = 1 4 = – 2n – 3 4 3 -n + 3 4 i. 3 -i = – 2n – 3 4 3 -n + 3 4

53
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. 10 + 3 n-i. i= 3 n. 10 + 3 n 3 -i. i= 3 n. 10 + 3 n i. 3 -i Suppose that we know the following theorem. i. 3 -i = – 2n – 3 4 3 -n + 3 4 = 3 n. 10 + 3 n ( – 2n – 3 4 3 -n + 3 4 ) = 3 n. 10 + – 2n – 3 4 + 3 n. 3 4 = 3 n. (10 + ) – 2n + 3 4 3 4 = 3 n. – 2n + 3 4 43 4

Similar presentations

© 2021 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google