Solving a recurrence T(n) = 2T(n/2) + n^4

huherto picture huherto · Jan 5, 2011 · Viewed 22.9k times · Source

I am studying using the MIT Courseware and the CLRS book Introduction to Algorithms.

I am currently trying to solve the recurrence (from page 107)

T(n) = 2T(n/2) + n4

If I make a recurrence tree, I get:

Level 0: n4

Level 1 2(n/2)4

Level 2 4(n/4)4

Level 3 8(n/8)4

The tree has lg(n) levels. Therefore I think that the recurrence should be

T(n) = Θ(n4 lg n)

But, If I use the master theorem, I get that

T(n) = Θ(n4)

Clearly both of these can't be right. Which one is correct? And where did I go wrong with my reasoning?

Answer

templatetypedef picture templatetypedef · Jan 5, 2011

The second one looks correct. Notice that your recurrence tree looks like

n4 + 2(n/2)4 + 4(n/4)4 + ... + 2i (n / 2i)4

But 2(n/2)4 ≠ n4, because (n/2)4 = n4 / 16, and so 2(n/2)4 = n4/8. In fact, if you work out the math, you get that the work being done at level i is given by

n4 / (2-3i)

So we get (1 + 1/8 + 1/64 + 1/512 + ... ) n4, which can be shown to be less than 2n4. So your function is Θ(n4).