0

I need to find the asymptotic upper bounds in $O$ notation for $T(N)$ in two recurrences. Assuming that $T(N)$ is constant for sufficiently small $N$, I need to make the bounds as tight as possible.

$T(N) = T(N-3) + 3 \log N$

$T(N) = 2T(N/4) + \sqrt{N}$

I know I should use master theorem. I can't implement it correctly to save my life. Can someone walk me through this

  • for the first one i've found that I can show T(3k)=T(0)+3klog3+3logk! then get the bound. not sure how to go about doing that. – crazyGracie Feb 08 '16 at 19:51
  • for the second one, i'm aware case 2 applies, but I have not ever implemented the master theorem personally and can not figure out how to do so. – crazyGracie Feb 08 '16 at 19:52
  • see e.g. http://math.stackexchange.com/questions/1489770/proving-asymptotic-barrier-o-notation? – Clement C. Feb 08 '16 at 20:10

2 Answers2

1

The Master Theorem will not get you anywhere for the first one, but would for the second.

  • For the first, why deal with the case $n=3k$, for a start? $$\begin{align} T(3k) &= T(3(k-1))+3\log (3k) = T(3k) = T(3(k-2))+3\log (3k)+3\log (3(k-1)) \\ &\vdots \\ &= T(3)+3\sum_{\ell=0}^{k-1} \log (3(k-\ell) = T(3) + 3k\log 3 + \sum_{\ell=1}^{k} \log \ell \\ &= T(3) + 3k \log 3 + (k\log k + o(k\log k)) = k\log k + o(k\log k) \\&= n\log n + o(n \log n) = \Theta(n \log n) \end{align} $$ and then see how to extend to $n=3k+1$ or $n=3k+2$.

  • for the second, the Master Theorem is indeed a good approach. You have $a=2$, $b=4$ and $f(n) = \sqrt{n}$. $\log_b a = \frac{1}{2}$, so that $$f(n) \in\Theta(n^{\log_b a} \log^0 n)$$ (second case applies for "$k=0$"). This yields $T(n) \in \Theta(n^{\log_b a} \log^1 n) = \Theta(\sqrt{n} \log n)$.


For the first part, I used the fact that $$ \sum_{\ell=1}^ k \log k = (1+o(1))k\log k. $$ If you don't know how to prove it, this is a good exercise -- and follows from a comparison series-integral: $$ \sum_{\ell=1}^ k \ln k \operatorname*{\sim}_{k\to\infty} \int_1^k \ln x dx = k\ln k - k +1. $$

Clement C.
  • 67,323
0

We first consider the first recurrence which, as has been stated, cannot be solved using the master theorem:

$$T(n) = T(n - 3) + 3 \log n $$

We expand the recurrence, getting:

$$ T(n) = 3 \log n + 3 \log (n - 3) + 3 \log (n - 6) + 3 \log (n - 9) + ... + 0 $$ $$ = \sum_{k = 0}^{\frac{n}{3}} 3 \log (n - 3k) = 3\sum_{k = 1}^{\frac{n}{3}} \log 3k$$ $$ = \sum_{k = 1}^{\frac{n}{3}} \left( 3 \log 3 + 3 \log k \right)$$ $$ = 3 \log 3 \sum_{k = 1}^{\frac{n}{3}} 1 + 3 \sum_{k = 1}^{\frac{n}{3}} \log k$$ $$ = n \log 3 + 3 \log \left( \frac{n}{3}! \right)$$

And so:

$$ T(n) = n \log 3 + 3 \log \left( \frac{n}{3}! \right) $$

Which we can verify using induction. Now, using Stirlings approximation:

$$ \log n! = \Theta(n \log n) $$

we get:

$$ T(n) = n \log 3 + 3 \frac{n}{3} \log \frac{n}{3} $$ $$ = n \log 3 + n \log n - n \log 3 = n \log n $$ $$ = \Theta(n \log n) $$

We now consider the second recurrence. The solution can be obtained using the master method, as pointed out by Clement C., but here we obtain it in the same way as we did for the first recurrence. Now, we have the recurrence:

$$ T(n) = 2T\left( \frac{n}{4} \right) + \sqrt{n} $$

Expanding the recurrence gives:

$$ T(n) = \sqrt{n} + 2 \sqrt{ \frac{n}{4}} + 2^2 \sqrt{ \frac{n}{4^2}} + 2^3 \sqrt{ \frac{n}{4^3}} + ... + 2^{\log_4 n} $$ $$ = \sum_{k = 0}^{\log_4 n} 2^k \sqrt{ \frac{n}{4^k}} = \sum_{k = 0}^{\log_4 n} \sqrt{n} $$ $$ = \sqrt{n} \sum_{k = 0}^{\log_4 n} 1 $$ $$ = \sqrt{n} \log_4 n = \Theta \left( \sqrt{n} \log_4 n \right) $$

which we can verify using induction.

prcssngnr
  • 1,191