Chapter 1: A Recurrance Solution

Analysis of Recursive Programs

Exercise 9.2 of Aho, Hopcroft, and Ullman. Solve the following recurrances, where T(1) = 1, and T(n) for n>=2 satisfies:
(a) T(n) = 3T(n/2) + n
(b) T(n) = 3T(n/2) + n2
(c) T(n) = 8T(n/2) + n3
"Solve" means "guess a solution and prove it is correct using induction." Assume that n is a power of 2. You may also note the following hints for the respective parts:

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:
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)

Induction hypothesis:
Assume THM is true: T(n) = 3T(n/2) + n < 3nlog2 3 - 2n for all n < n'.

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


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

Here I will consider the recurrance relation:

Suppose
T(1) = 1
T(n) = 3T(n/2) + n
then
R(0) = 1 and
R(k) = 3R(k-1) + 2k

With the hint that there is a term cnlog2 3. With n=2k, substituting for n, this looks like
c(2k)log2 3
= c(2log2 3)k
= c * 3k

With the hint, we expected something like cnlog 3 + bn.
So, a guess of R(k)= c * 3k + b* 2k looks like the R(k) expression.

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
c * 3k + b* 2k =? 3(c * 3k-1 + b* 2k-1) + 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

OK, this recurrance relation guess (3nlog2 3 - 2n) looks good - let b = -2. Proof by induction (done above)