\documentclass[11pt]{article}

%\setlength{\topmargin}{-.8in}  
% \setlength{\oddsidemargin}{0in}
% \setlength{\evensidemargin}{0in}
% \setlength{\textwidth}{6.5in}
% \setlength{\textheight}{9.5in}

\usepackage{graphicx}
\usepackage{fullpage}
\begin{document}

\title{Class work: Recurrence example}
\date{}
\maketitle


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Consider the following recurrence which is very similar to the one for
Mergesort:

$$T(n) = 3T(n/3) + n $$

Solve it (i.e. give a $\Theta()$-bound for $T(n)$. 


{\bf Answer:}
\begin{eqnarray*}
T(n) & = & 3T(n/3)  + n\\
     & = & 3(3T(n/9) + n/3) ) + n\\
     & = & 9 T(n/9) + 2n \\
     & = & 9 (3T(n/27 + n/9) + 2n\\
     & = & 27 T(n/27) + 3n\\
     & = & \dots \\
     & = & 3^i T(n/3^i) + i\cdot n\\
\end{eqnarray*}


\begin{itemize}
\item Recursion depth: How long (how many iterations) it takes until
  the subproblem has constant size?  $i$ iterations,  where
  $\frac{n}{3^i}=1 \Rightarrow i=\log_3 n$
  
\item What is the last term? $3^iT(1)=3^{\log_3 n} T(1) = n \cdot 1 =
  n$ 
  
So we have: 
  \begin{eqnarray*}
    T(n) & = & 3^{\log_3 n} T(1) + \log_3 n \\
    & = & n + \log_3 n \cdot n \\
    & = & \Theta(n \lg n)
  \end{eqnarray*}
  
\end{itemize}



\end{document}
