6

I'm reading through Introduction to Algorithms, 3rd ed. and I got stuck on the following recurrence (exercise 4.4-5):

$$T(n) = T(n - 1) + T(n/2) + n$$

The exercise asks you to find the upper bound using the recurrence-tree method. I tried drawing one. It would have $2^n$ leafs if it was a complete binary tree (the height is $n$), but it is not. Furthermore, I cannot find a formula that expresses the complexity of each level like they do in the book.

After writing some code to calculate $T(n)$ and comparing it with different functions, I end up thinking that the complexity is exponential. Using $c2^n$ with the substitution method works out, but I'm not certain that this is a tight bound. I'm not certain that the tight bound is exponential either.

Can somebody help me out through the reasoning?

P.S.: If it matters, I'm not in school/university and this is not homework. I'm a (let's say) Ruby programmer who is self-studying to fill in his gaps in Computer Science.

1 Answers1

3

I end up thinking that the complexity is exponential.

Not so.

A previous answer asserted correctly that $T(n)\geqslant\frac12n^2$ and wrongly that the property $T(n)\leqslant cn^2$ is hereditary (that is, if it holds for every $k\leqslant n-1$ it holds for $n$) for every $c\geqslant2$.

In fact, the property $T(n)\leqslant cn^2$ is not hereditary and the complexity is neither polynomial nor exponential. It seems that $\log T(n)\sim(\log n)^2/(2\log2)$ and one can probably check that, for every positive $\varepsilon$, the property $$ \exp((\log n)^{2-\varepsilon})\leqslant T(n)\leqslant\exp((\log n)^{2+\varepsilon}) $$ is hereditary for every $n$ large enough.

Did
  • 279,727
  • Thanks for your answer, but I'm not certain I can follow it through. You don't seem to take into account the $T(n/2)$ term. While I can see why $T(n) = T(n-1) + n$ is $n^2$, I'm not certain how the added $T(n/2)$ affects it. – Stefan Kanev Aug 24 '13 at 16:10
  • Or rather, I follow the lower bound logic, but I don't understand how you come up with the upper bound guess. – Stefan Kanev Aug 24 '13 at 16:12
  • This fully takes into account the T(n/2) term, thank you. How should I spell "you might want to check that the property ... is hereditary"? Did you (check it was)? "I'm not certain how the added T(n/2) affects it"... You would be (certain how the added term affects it) if you had checked. – Did Aug 24 '13 at 16:18
  • How I came up with the upper bound guess: n/2 is much deeper into the tree than n-1 hence I conjectured than the behaviour of T(n) was ruled by the T(n-1)+n part of the recursion, that is, that T(n) was growing roughly as n^2. Then I checked the conjecture. – Did Aug 24 '13 at 16:20
  • Fair enough. Thanks for your help :) – Stefan Kanev Aug 24 '13 at 16:20
  • @Did The upper bound does not hold (i.e. $T(n)\leq cn^2$ is not hereditary); you get $\frac{5}{4}cn^2$ as the main term if you plug it into the recurrence, which is obviously not bounded by $cn^2$ for any positive $c$. The sequence is actually growing faster than any polynomial, but slower than any exponential. – Peter Košinár Aug 24 '13 at 23:32
  • @PeterKošinár Obviously you are right. Thanks for your comment and sorry for the noise. – Did Aug 24 '13 at 23:56