

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


ECS122A: Algorithm Design and Analysis Homework Assignment #2 Solutions
(n + a)b^ = Θ(nb).
Solution: We need to show that there are constants c 1 , c 2 , n 0 > 0 such that 0 ≤ c 1 nb^ ≤ (n + a)b^ ≤ c 2 nb^ for all n ≥ n 0. Note that
n + a ≤ n + |a| ≤ 2 n when n ≥ |a|.
and n + a ≥ n − |a| ≥
n when n ≥ 2 |a|.
Thus, when n ≥ 2 |a|, 0 ≤
n ≤ n + a ≤ 2 n. Since b > 0, the inequality still holds when all parts are raised to the power b:
( 1 2
n
)b ≤ (n + a)b^ ≤ (2n)b.
Thus, c 1 = (1/2)b, c 2 = 2b, and n 0 = ⌈ 2 |a|⌉.
n 2 n^ n lg n n^3 n^2 lg n n − n^3 + 7n^5 n^2 + lg n
Solution: (a) lg n, n, n lg n, n^2 (≈ n^2 + lg n), n^3 , n − n^3 + 7n^5 , 2 n
(b) Combine the following functions into your answer for part (a). Assume that 0 < ǫ < 1.
en^
n 2 n−^1 lg lg n (
2)lg^ n ln n (lg n)^2 n! n1+ǫ^1
Solution: (b) 1 lg lg n, lg n(≈ ln n), (lg n)^2 , √ n = (
2)lg^ n, n, n lg n, n1+ǫ, n^2 (≈ n^2 + lg n), n^3 , n − n^3 + 7n^5 , 2 n(≈ 2 n−^1 ), en, n! The problem does not ask you to justify these relations (otherwise, it will be too long!). But here is an example. Why n lg n = O(n1+ǫ)? We can compute limn→∞[n lg n/n1+ǫ] = 0 (using L’Hopital’s rule).
Solution: (a) This is a divide-and-conquer recurrence with a = 4, b = 2 and f (n) = n, and nlogb^ a^ = nlog^2 4 = n^2. The quotient f (n) nlogb^ a^
n n^2
n
Case 1 of the master theorem applies, and T (n) = Θ(nlogb^ a) = Θ(n^2 ). (b) In this divide-and-conquer recurrence, a = 4, b = 2 and f (n) = n^2 , and nlogb^ a^ = nlog^2 4 = n^2. The quotient f (n) nlogb^ a^
n^1 n^2
Case 2 of the master theorem applies, and T (n) = Θ(nlogb^ a^ lg n) = Θ(n^2 lg n). (c) In this divide-and-conquer recurrence, a = 4, b = 2 and f (n) = n^3 , and nlogb^ a^ = nlog^2 4 = n^2. The quotient f (n) nlogb^ a^
n^3 n^2
= n.
Case 3 of the master theorem applies, and T (n) = Θ(f (n)) = Θ(n^3 ).