I will show work on (a)
T(n) = 3T(n/2) + n.
Given the hint, a good guess is T(n) < cnlog2 3 + bn
Even better: T(n) < cnlog2 3 - 2n
For how this good guess came about, see below
Prove using induction:
PROOF:
Base:
Induction hypothesis:
Induction step: Suppose n is greater than n', let n = n' + 1
then, T (n) = 3T(n/2) + n (by definition of T(n))
since n/2 < n', by induction hypothesis, T (n/2) = 3(n/2log2 3) - 2(n/2)
Hence, by induction on n
T(n) < 3nlog2 3 - 2n
is true for all n > 1.
and T(n) is O(nlog2 3)
More on the handout
Here I will consider the recurrance relation:
Suppose
With the hint that there is a term cnlog2 3. With n=2k, substituting for n, this looks like
With the hint, we expected something like cnlog 3 + bn.
Let's try this R(k)= c * 3k + b* 2k . (I.E., does it work for our definition of R(k)?)
R(k) = 3R(k-1) + 2k
OK, this recurrance relation guess (3nlog2 3 - 2n) looks good - let b = -2. Proof by induction (done above)
T(1) = 1 by definition
T(1) < c*1log 3 - 2*1 (assume logs are always base 2) implies
1 < c - 2 implies
3 < c (OK, remember this - use for c)
Assume THM is true: T(n) = 3T(n/2) + n < 3nlog2 3 - 2n for all n < n'.
Sometimes we find a recurrance and/or prove by induction on k rather than n. We can do this because of the relationship that 2k=n.
Consider relations between r and n
T(1) = 1
T(n) = 3T(n/2) + n
then
R(0) = 1 and
R(k) = 3R(k-1) + 2k
c(2k)log2 3
= c(2log2 3)k
= c * 3k
So, a guess of R(k)= c * 3k + b* 2k looks like the R(k) expression.
c * 3k + b* 2k =? 3(c * 3k-1 + b* 2k-1) + 2k
c * 3k = 3(c * 3k-1) so take this off of both sides... and 3(b* 2k-1) is 3*1/2 (b* 2k)
So, we need to show b* 2k = (3/2)* b*2k + 2k (divide by 2k)
b = (3/2)b + 1
-b/2= 1
b= -2