Professional Documents
Culture Documents
1. 0.2 from text book. Show that, if c is a positive real number, then g(n) =
1 + c + c2 + + cn is
(a) (1) if c < 1
(b) (n) if c = 1
(c) (cn ) if c > 1
The moral: in big- terms, the sum of a geometric series is simply the first
term if the series is strictly decreasing, the last term if the series is strictly
increasing, of the number of terms if the series is unchanging. (Question
0.2 from the text.)
Solution: First, we note that a geometric series has a closed-form solution:
cn+1 1
g(n) = 1 + c + c2 + ... + cn =
c1
If c < 1, we have:
lim g(n) =
01
1
=
(since limn cn+1 = 0)
c1
1c
1
cn
= 0 for c > 1)
This allows us to conclude that g(n) = (cn ) for c > 1. Thus, we have
g(n) = (cn ).
1
2T (n/2) + cn
(a) Do the same thing for the recurrence T (n) = 3T (n/2) + O(n). What
is the general kth term in this case? And what value of k should be
plugged in to get the answer?
(b) Now try the recurrence T (n) = T (n 1) + O(1), a case which is not
covered by the master theorem. Can you solve this too?
Solution:
(a) From the recurrence relation, T (n) 3T (n/2) + cn for some constant
c. So:
T (n)
3T (n/2) + cn
32 (3T (n/8) + cn/4) + (3/2 + 1)cn = 33 T (n/23 ) + (32 /22 + 3/2 + 1)cn
k
X
(3/2)i
i=0
k
n
1/2
l
n
m
n2n
n
2n
o
n!
log n
p
(log
Pnn) k
q
i=1 i
g(n)
n 200
n2/3
n + (log n)2
10n log 10n
log 3n
log(n2 )
n(log n)2
n(log n)2
(log n)10
n/ log n
(log n)3
5log2 n
3n
n+1
2
2n
(log2 n)2
2
nk+1
f = O(g)?
yes
yes
yes
yes
yes
yes
no
no
no
no
no
yes
yes
yes
no
yes
yes
f = (g)?
yes
no
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
no
yes
yes
no
yes
f = (g)?
yes
no
yes
yes
yes
yes
no
no
no
no
no
no
no
yes
no
no
yes
T (n) = O(nlog3 2 )
T (n) = O(nlog4 5 )
T (n) = O(n log7 n)
T (n) = O(n2 log3 n)
T (n) = O(n3 log2 n)
T (n) = O(n3/2 log n)
T (n) = O(n)
Pn
T (n) = nc + (n 1)c + ... + 1c = i=1 ic = O(nc+1 )
Pn
T (n) = i=1 ci = O(cn )
T (n) = O(2n )
k
=
<
=
=
=
=
>
>
>
>
>
<
<
=
>
<
=