1
$\begingroup$

I encountered these few recursive relations:

T(n) = (n/2)T(n/2) + O(n^2)

T(n) = T(n/2) + T(n/2-1) + ... + T(1) + O(n^2)

I do notice that these recursions can be solved faster by DP. I'm just curious as to:

  1. What's the big-O of the running time of these relations, if we follow the resursive formula
  2. How do you analysis recursive relations like these.
  3. Does the trailing term (in this case O(n^2)) matter?

Any help is much appreciated.

$\endgroup$
2
  • 1
    $\begingroup$ What have you tried? What research have you done? We expect you to make a serious effort on your own, and to do some research before asking. Did you read our reference question on solving recurrence relations? cs.stackexchange.com/q/2789/755 It looks like it should answer your questions. $\endgroup$
    – D.W.
    Nov 13 '13 at 19:23
  • $\begingroup$ Note that the question "What's the big-O of the running time of these relations" seems ill-posed. Are you intested in a closed form for $T(n)$, or are you interested in calculating the value of $T(n)$ algorithmically? $\endgroup$
    – Raphael
    Nov 13 '13 at 21:56
1
$\begingroup$

You can solve the first recurrence for powers of $2$. The recurrence (without the big O and with an arbitrary base case) reads $$ T(2^k) = 2^{k-1} T(2^{k-1}) + 4^k, \quad T(2^0) = 4^0. $$ Opening the recurrence, we get $$ T(2^k) = 4^k + 2^{k-1} \cdot 4^{k-1} + 2^{k-1+k-2} \cdot 4^{k-2} + \cdots + 2^{k-2+\cdots+1} 4^0. $$ Denote these by $T(2^k) = \alpha_0 + \cdots + \alpha_\ell$. We have $$ \frac{\alpha_\ell}{\alpha_{\ell-1}} = 2^{k-\ell-1}. $$ Therefore the largest term is $\alpha_{k-1} = \alpha_{k-2}$, and the rest of the terms decrease geometrically. This shows that $$ T(2^k) = \Theta(\alpha_{k-1}) = \Theta(2^{k-1+\cdots+1} 4^1) = \Theta(2^{k(k-1)/2}). $$ As you can see, the term $O(n^2)$ in the recurrence isn't important, and you will get similar result for any term $O(n^c)$.

One could guess that the general solution to the first recurrence (with $\lfloor n/2 \rfloor$ replacing $n/2$) is $T(n) \Theta(2^{\log_2 n(\log_2 n - 1)/2})$, and one could further guess that the second recurrence has the same solution (though that's a wilder guess). I'm not sure these guesses are correct. At the very least, the first recurrence should have the solution $T(n) = 2^{\Theta(\log^2 n)}$.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.