next up previous
Up: Previous:

Iteration


\begin{displaymath}T(n) \;=\; n^3 \;+\; 2T(n/2)\end{displaymath}


\begin{displaymath}=\; n^3 \;+\; 2[(n/2)^3 \;+\; 2T(n/4)]\end{displaymath}


\begin{displaymath}=\; n^3 \;+\; \frac{n^3}{2^2} \;+\; 4T(n/4)\end{displaymath}


\begin{displaymath}=\; n^3 \;+\; \frac{n^3}{2^2} \;+\; 4[(n/4)^3 \;+\; 2T(n/8)]\end{displaymath}


\begin{displaymath}=\; n^3 \;+\; \frac{n^3}{2^2} \;+\; \frac{n^3}{4^2} \;+\; 8T(n/8)\end{displaymath}

These are terms i=0, i=1, i=2, i=3

\begin{displaymath}=\; n^3 \;+\; \frac{n^3}{2^2} \;+\; \frac{n^3}{4^2} \;+\; \frac{n^3}{8^2}
\;+\; ... \;+\; 2^i T(\frac{n}{2^i})\end{displaymath}

Terminates when n/2i = 2, T(2) = $\Theta(1)$.
n = 2i+1, lgn = i+1, i = lgn - 1

\begin{displaymath}=\; \sum_{i=0}^{lgn - 2}\frac{n^3}{(2^i)^2} \;+\; 2^{lgn - 1} T(2)\end{displaymath}


\begin{displaymath}=\; n^3 \sum_{i=0}^{lgn - 2} \; (1/4)^i \;+\; 1/2 n \Theta(1)\end{displaymath}


\begin{displaymath}=\; n^3 (\frac{(1/4)^{lgn - 1} - 1}{1/4 - 1}) \;+\; 1/2 \Theta(n)\end{displaymath}


\begin{displaymath}=\; n^3 (\frac{1 - (2^{-2})^{lgn - 1}}{3/4}) \;+\; \Theta(n)\end{displaymath}

Note that (1/4)lgn - 1 = 2-2 lg n + 2
= \(2^{lg n^{-2}} \;*\; 4\) = 4 n-2

\begin{displaymath}=\; 4/3n^3 (1 - 4n^{-2}) \;+\; \Theta(n)\end{displaymath}


\begin{displaymath}=\; 4/3n^3 - 16/3n + \Theta(n)\end{displaymath}


\begin{displaymath}=\; \Theta(n^3)\end{displaymath}


next up previous
Up: Previous: