Professional Documents
Culture Documents
Solution
(Time: 1.5 Hours)
n 10
T (n)
n 100
Notes:
For () proof, n 10 would not work as it would result in negative constant C. (The
constants C and n0 must be positive.)
For O(), we picked n 10 and for () we picked n 100. So we see that the n0 values
for the two cases need not be the same. Why? Let n1 = max{10, 100}. Then both proofs
would still be valid for n n1 .
f (n) =
0,
n=1
2f (n/2) + 1, n > 1
(c) (6 pts.) Find the solution of the recurrence by repeated substitution. Then express the
asymptotic time complexity of the algorithm.
1 + 2 + 4 + + 2k1 + 2k f (n/2k )
1 + 2 + 4 + + 2k1 + 2k f (1)
1 + 2 + 4 + + 2k1 (geometric series sum)
2k 1 = n 1.
f (n) =
1,
n=1
2f (n 1) + 1, n > 1.
T (n) =
1,
n=1
8T (n/2) + n2 , n > 1
n2 + 8T (n/2)
n2 + 8((n/2)2 + 8T (n/4))
n2 + 2n2 + 82 T (n/22 )
n2 + 2n2 + 22 n2 + 83 T (n/23 )
..
.
n2 (1 + 2 + 22 + + 2k1 ) + 8k T (n/2k )
n2 (2k 1) + (2k )3 T (1)
n2 (n 1) + n3
2n3 n2 .
(1)
T (n) =
0,
n=1
2T (n/2) + log n, n > 1
2T (n/2) + log n
2(An/2 + B log(n/2) + C) + log n, (from hypothesis)
An + 2B(log n log 2) + 2C + log n
An + (2B + 1) log n 2B + 2C
An + B log n + C,
2B + 1 = B,
So, we have:
A+C = 0
2B + 1 = B
2B + 2C = C.
Thus, A = 2, B = 1, C = 2. Therefore,
T (n) = 2n log n 2.