Problem Set 4 4.4-4 Use a recursion tree to determine a good asymptotic upper bound on the recurrence T (n) = 2T (n − 1) + 1. Use the substitution method to verify your answer. Using a recursion tree or 'unwrapping' the recurrence relation allows one to conclude that T (n) = 2T (n − 1) + 1 = 2 (2T (n − 2) + 1) + 1 = 22 T (n − 2) + 1 + 2 .. . = 2k T (n − k) + 1 + 2 + . . . 2k−1 This terminates at n − k = 1, i.e. k = n − 1. Then Pn=2 T (n) = 2n−1 T (1) + i=0 2i = c2n (noting 2n−1 = 12 2n ). The asymptotic upper bound that this suggests is T (n) = Θ (2n ). You will nd that guessing T (n) ≤ c2n doesn't quite work, though. Instead, guess T (n) ≤ c2n − d. For xed d, c can be made suciently large that the inequality is true for n = 1. The inductive hypothesis allows us to conclude n−1 T (n) = 2T (n − 1) + 1 ≤ 2 c2 ≤ c2n − 2d + 1. or −d +1 In order to conclude T (n) ≤ c2n − d , we need that c2n − 2d + 1 ≤ c2n − d, −2d + 1 ≤ −d 1 ≤ d. Setting d = 1 and allowing c to be as large as necessary to make the base case true, completes the proof that T (n) ≤ c2n − 1, so T (n) = O (2n ). 4-1 Give asymptotic upper and lower bounds for T (n) in each of the following recurrences. Assume T (n) is constant for n ≤ 2. Make your bounds as tight as possible, and justify your answers. a. T (n) = 2T (n/2) + n4 : T (n) = Θ n4 : in terms of the Master Theorem, 4 logb a+3 a = 2, b = 2, so logb a = log2 2 = ; this is looking like 1. f (n) = n = n n case 3. We need to check af b ≤ cf (n) for some c < 1 and n large enough. 4 In fact, af nb = 2 n2 = 18 n4 = 81 f (n), and case 3 applies. Conclude T (n) = Θ n4 . b. T (n) = T (7n/10) + n: T (n) = Θ (n) : in terms of the Master Theorem, logb a+1 10 a = 1, b = 10 ; this is looking like 7 , so logb a = log 7 1 = 0. f (n) = n = n n case 3. We need to check af b ≤ cf (n) for some c < 1 and n large enough. 1 7 7 In fact, af nb = 1 7n = 10 n = 10 f (n), and case 3 applies. 10 1 Conclude T (n) = Θ (n). c. T (n) = 16T (n/4) + n2 : T (n) = Θ n2 lg n : in terms of the Master Theorem, a = 16, b = 4, so logb a = log4 16 = 2. f (n) = n2 = nlogb a ; this is case 2. Conclude T (n) = Θ n2 lg n . d. T (n) = 7T (n/3) + n2 : T (n) = Θ n2 lg n : in terms of the Master Theorem, a = 7, b = 3, so 1 < logb a = log3 7 < 2. f (n) = n2 = nlogb a+ε for some ε > 0; this is looking like case 3. We need to check af nb ≤ cf (n) for 2 some c < 1 and n large enough. In fact, af nb = 7 n3 = 79 n2 = 79 f (n), and case 3 applies. Conclude T (n) = Θ n2 lg n . e. T (n) = 7T (n/2)+n2 : T (n) = Θ nlog2 7 : in terms of the Master Theorem, 2 logb a−ε a = 7, b = 2, so 2 < logb a = log ; this is case 1. 2 7 < 3. f (n) = n = n log2 7 Conclude T (n) = Θ n . √ √ f. T (n) = 2T (n/4) + n: T (n) = Θ ( n lg n): in terms of the Master 1 Theorem, a = 2, b = 4, so logb a = log4 2 = 12 . f (n) = n 2 = nlogb a ; this is case 2. √ Conclude T (n) = Θ ( n lg n). g. T (n) = T (n−2)+n2 : T (n) = Θ n3 : the Master Theorem doesn't apply. A recursion tree or 'unwrapping' the recurrence relation allows one to conclude 2 2 T (n) = T (n − 2k) + n2 + (n − 2) + . . . (n − 2 (k − 1)) . n For odd n, set k = b 2 c to get Pb n2 c−1 Pn−1 Pn 2 2 T (n) = T (1)+ i=0 (n − 2i) ≤ T (1)+ i=0 (n − i) = T (1)+ i=1 n2 = . This last expression is Θ n3 , allowing us to conclude that T (1) + n(n+1)(2n+1) 6 T (n) = O n3 . For a lower bound,n Pb c−1 2 T (n) = T (1) + i=0 (n − 2i)2 2 2 2 1 2 = T (1) + n + (n − 2) + (n − 4)2 + . . . 32 (n − 4) + . . . 2 3 = T (1) + 1 2 2 Pn−2 i=0 (n − 2i)2 ≥ T (1) + 1 2 2 Pb n2 c−1 i=0 (n − 2i)2 = T (1)+ 21 n2 + 21 n2 + 12 (n − 2)2 + 21 (n − 2)2 + 12 (n − 4)2 + 21 (n − 4)2 +. . . 12 3+ 21 3. ≥ T (1) + 12 n2 + 12 (n − 1)2 + 21 (n − 2)2 + 12 (n − 3)2 + 12 (n − 4)2 + 12 (n − 5)2 + 1 . . . 2 3 + 21 2 Pn ≥ T (1) + 21 i=2 n2 = T (1) + n(n+1)(2n+1) − 12 . 12 This last expression is Θ n3 , allowing us to conclude that T (n) = Ω n3 . A similar argument, using T (0) as the base, gives the same asymptotic bounds for n even. Conclude T (n) = Θ n3 . 2
© Copyright 2026 Paperzz