Professional Documents
Culture Documents
Hwk1 Solution
Hwk1 Solution
Hwk1 Solution
Homework Set 1
Student Name: Khaled Gamal Abdel Maksoud
Student ID: 1280703
b. f(n) = O(g(n)) implies lg(f(n)) = O(lg(g(n))), where lg(g(n)) ≥ 1 and f(n)≥ 1 for all sufficiently large n.
Solution
Since f(n) = O(g(n)) then, there exist constants C > 0 and n0 > 0 such that 0 ≤ f(n) ≤ C g(n) for all n ≥ n0
lg(f(n)) ≤ lg(C g(n)) [ since lg is a monotone function ]
lg(f(n)) ≤ lg(C) + lg(g(n)) [ since lg(ab) = lg(a) + lg(b) ]
lg(f(n)) ≤ d + lg(g(n)) where d = lg(C)
If d ≥ 0 then, lg(f(n)) ≤ d lg(g(n)) + lg(g(n)) [ since lg(g(n)) ≥ 1 ]
lg(f(n)) ≤ (d+1) lg(g(n))
lg(f(n)) ≤ k lg(g(n)) where k = d+1
lg(f(n)) = O(lg(g(n)))
If d < 0 then, lg(f(n)) ≤ lg(g(n))
Page 1 of 8
lg(f(n)) ≤ k lg(g(n)) where k = 1
lg(f(n)) = O(lg(g(n)))
Therefore, the conjecture “f(n) = O(g(n)) implies lg(f(n)) = O(lg(g(n))), where lg(g(n)) ≥ 1 and f(n)≥ 1 for all
sufficiently large n” is always true.
d. f(n) = O((f(n))2).
Solution
Let f(n) = n
It is clear that f(n) = O((f(n))2) since 0 ≤ n ≤ C n2 where C is a constant ≥ 1 and for all n ≥ 1
Now, let f(n) = 1/n
It is clear that f(n) ≠ O((f(n))2) since we cannot find constants C > 0 and n0 > 0 such that 0 ≤ 1/n ≤ C (1/n)2 for
all n ≥ n0 ( since 1/n grows faster than (1/n)2 )
Therefore, the conjecture “f(n) = O((f(n))2)” is not always true.
Page 3 of 8
Problem 2 (20 points)
a) Use a recursion tree to determine a good asymptotic upper bound on the recurrence
𝑇(𝑛) = 𝑇(𝑛⁄2) + 𝑛2
Solution
T(n) n2 n2 n2 n2 n2
Depth = lg n
T(n/8) (n/8)2 (1/4)3 n2
∞
≤ [∑i=0 (1/4)i n2 ] + C
= 4/3 n2 + C
≤ 4/3 n2 + C n2
= (4/3 + C) n2
= d n2 (where d = 4/3 + C)
We have T(n) ≤ d n2 where d is a constant > 0 and n ≥ 1.
Therefore, T(n) = O(n2 ).
Page 4 of 8
b) Use the substitution method to verify your answer
Solution
Assume T(k) ≤ C k2 for k < n and C is a constant > 0.
T(n) = T(n/2) + n2
≤ C (n/2)2 + n2
= C n2/4 + n2
3
= C n2 - (4 C n2 − n2 ) (desired - residual)
3
≤ C n2 whenever (4 C n2 − n2 ) ≥ 0
Page 5 of 8
Problem 3 (20 points)
Use the master method to give tight asymptotic bounds for the following recurrences.
a) 𝑇(𝑛) = 2𝑇(𝑛⁄2) + 𝑛4
Solution
Comparing the given recurrence with the general form T(n) = a T(n/b) + f(n), we get:
a = 2, b = 2 and f(n) = 𝑛4 (f(n) > 0 for all n ≥ 1)
𝑛log𝑏 𝑎 = 𝑛log𝑏 𝑎 = 𝑛
𝑛4 = Ω(𝑛1+ℇ ) for some ℇ > 0
𝑛4 = Ω(𝑛2 ) (we selected ℇ = 1)
Now, we need to prove that a f(n/b) ≤ C f(n) for some positive constants C and n0 where C < 1 and n ≥ n0
2(𝑛/2)4 ≤ C 𝑛4
C = 1/8 and n ≥ 1
It is clear now that we can apply Case 3 of the master method.
Therefore, T(n) = Θ(𝑛4 )
b) 𝑇(𝑛) = 𝑇(7𝑛⁄10) + 𝑛
Solution
Comparing the given recurrence with the general form T(n) = a T(n/b) + f(n), we get:
a = 1, b = 10/7 and f(n) = 𝑛 (f(n) > 0 for all n ≥ 1)
𝑛log𝑏 𝑎 = 𝑛log10/7 1 = 𝑛0
𝑛 = Ω(𝑛0+ℇ ) for some ℇ > 0
𝑛 = Ω(𝑛) (we selected ℇ = 1)
Now, we need to prove that a f(n/b) ≤ C f(n) for some positive constants C and n0 where C < 1 and n ≥ n0
7n/10 ≤ C 𝑛
C = 7/10 and n ≥ 1
It is clear now that we can apply Case 3 of the master method.
Therefore, T(n) = Θ(𝑛)
c) 𝑇(𝑛) = 16𝑇(𝑛⁄4) + 𝑛2
Solution
Comparing the given recurrence with the general form T(n) = a T(n/b) + f(n), we get:
a = 16, b = 4 and f(n) = 𝑛2 (f(n) > 0 for all n ≥ 1)
Page 6 of 8
𝑛log𝑏 𝑎 = 𝑛log4 16 = 𝑛2
𝑛2 = Θ (𝑛2 ) (since 1/2 𝑛2 ≤ 𝑛2 ≤ 2 𝑛2 for all n ≥ 1)
It is clear now that we can apply Case 2 of the master method.
Therefore, T(n) = Θ(𝑛2 lg 𝑛)
d) 𝑇(𝑛) = 7𝑇(𝑛⁄3) + 𝑛2
Solution
Comparing the given recurrence with the general form T(n) = a T(n/b) + f(n), we get:
a = 7, b = 3 and f(n) = 𝑛2 (f(n) > 0 for all n ≥ 1)
𝑛log𝑏 𝑎 = 𝑛log3 7 = 𝑛𝑑 where 1 < d < 2
𝑛2 = Ω(𝑛𝑑+ℇ ) for some ℇ > 0
𝑛2 = Ω(𝑛2 ) (we selected ℇ = 2-d > 0)
Now, we need to prove that a f(n/b) ≤ C f(n) for some positive constants C and n0 where C < 1 and n ≥ n0
7(𝑛/3)2 ≤ C 𝑛2
C = 7/9 and n ≥ 1
It is clear now that we can apply Case 3 of the master method.
Therefore, T(n) = Θ(𝑛2 )
e) 𝑇(𝑛) = 7𝑇(𝑛⁄2) + 𝑛2
Solution
Comparing the given recurrence with the general form T(n) = a T(n/b) + f(n), we get:
a = 7, b = 2 and f(n) = 𝑛2 (f(n) > 0 for all n ≥ 1)
𝑛log𝑏 𝑎 = 𝑛log2 7 = 𝑛𝑑 where 2 < d < 3
𝑛2 = O(𝑛𝑑−ℇ ) for some ℇ > 0
𝑛2 = O(𝑛2 ) (we selected ℇ = d-2 > 0)
It is clear now that we can apply Case 1 of the master method.
Therefore, T(n) = Θ(𝑛log2 7)
f) 𝑇(𝑛) = 2𝑇(𝑛⁄4) + √𝑛
Solution
Comparing the given recurrence with the general form T(n) = a T(n/b) + f(n), we get:
Page 7 of 8
a = 2, b = 4 and f(n) = √𝑛 (f(n) > 0 for all n ≥ 1)
𝑛log𝑏 𝑎 = 𝑛log4 2 = √𝑛
√𝑛 = Θ (√𝑛) (since 1/2√𝑛 ≤ √𝑛 ≤ 2 √𝑛 for all n ≥ 1)
It is clear now that we can apply Case 2 of the master method.
Therefore, T(n) = Θ(√𝑛 lg 𝑛)
g) 𝑇(𝑛) = 𝑇(𝑛 − 2) + 𝑛2
Solution
We cannot apply the master method since the given recurrence does not comply with the general form:
T(n) = a T(n/b) + f(n) (the problem size does not decrease by a factor of 1/b for some b > 1).
Page 8 of 8