\documentclass{article}
\usepackage{amsmath}
\advance\textwidth by1.4in\advance\oddsidemargin by-0.7in
\advance\textheight by1.1in\headheight 0pt\topskip 0pt\headsep 0pt\topmargin 0pt
\begin{document}
\thispagestyle{empty}
\begin{center}
  \large\bf CS 561\ \ Data Structures and Algorithms II\\
  \bigskip

  \large\it Homework \#1
\end{center}

\bigskip
\emph{Problem 1.}   
\begin{itemize}
  \item
    We are given $f(n) = 3f(n-1) + 1$; unrolling it from the top yields
    $$f(n) = 3f(n-1) + 1 = 3\cdot(3f(n-2) + 1) + 1 = 9f(n-2) + 3 + 1 =$$
    $$ 9\cdot (3f(n-3) + 1) + 3 + 1 = 27f(n-3) + 9 + 3 + 1 =$$
    $$ 27\cdot (3f(n-4) + 1) + 9 + 3 + 1 = 81f(n-4) + 27 + 9 + 3 + 1 ldots$$
    Since we have $f(0) = 0$, it is clear that the formula unrolls to
    $3^{n-1} + 3^{n-2} + \ldots + 3^1 + 3^0$, or, more precisely
    and concisely, $\sum_{i=0}^{n-1} 3^i$.  In passing, note that this implies
    means the $f$ is also defined by the (simpler) recurrence
    $f(n) = f(n-1) + 3^{n-1}$.  An exact closed form is not too hard to
    obtain: $f(n) = \frac12 (3^n - 1)$.

    It might be a bit harder from the bottom, where we get successive values
    0, 1, 4, 13, 40, 121, etc.; the trick there is to notice that twice this
    series is more interesting: 0, 2, 8, 26, 80, 242, etc., since now every
    term is a power of 3 minus 1.
  \item
    The recurrence  is $f(n) = 2f(n/4) + 1$; unrolling it from the top yields
    $$f(n) = 2f(n/4)+1 = 2\cdot(2f(n/16)+1) + 1 = 4f(n/16) + 2 + 1 =$$
    $$4\cdot(2f(n/64)+1) + 2 + 1 = 8f(n/64) + 4 + 2 + 1 = $$
    $$8\cdot(2f(n/256)+1) + 4 + 2 + 1 = 16f(n/256) + 8 + 4 + 2 + 1 = $$
    It's now clear that we will get a sum of powers of 2; for each new power
    of 2 we get in the sum, the current value of $n$ is divided by 4, so the
    sum will be over $\log_4 n$ terms.  If we write $n=4^k$, the sum will be
    over $k$ terms and so we'll get $\sum_{i=0}^{k-1} 2^i$, which is just
    $2^k - 1$, or $2^{\log_4 n} -1$; simplifying, we get
    $f(n) = 2^{\log_4 n} -1 = 2^{\log_4 2 \log_2 n} -1 = n^{\log_4 2} -1 = \sqrt{n} -1$

    Once again, going from the bottom is trickier: for $n=1,4,16,64,256,\ldots$,
    we get $f(n)=1,3,7,15,31,\ldots$; that series is obviously powers of 2
    minus 1, but the trick is relating it to the values of $n$.
\end{itemize}

\bigskip
\emph{Problem 2.}   
\begin{itemize}
  \item
  The recurrence is of order 2 and is homogeneous with constant coefficients.
  The characteristic equation is $r^2=5r-6$, with solutions $r_1=2$
  and $r_2=3$.  In asymptotic terms, the root $3$ dominates, so we can
  write $f(n) = \Theta(3^n)$.
  \item
  The recurrence is of order 2 and is homogeneous with constant coefficients.
  The characteristic equation is $r^2=2r-1$, with solutions $r_1=r_2=1$.
  Because the root of value 1 has multiplicity 2, the (homogeneous) solution
  is a polynomial of degree 1 times the exponential in the root, i.e., it is
  of the form $(\alpha + \beta\cdot n)\cdot 1^n$, which is asymptotically
  just $\Theta(n)$.
  \item
  The recurrence is of order 3 and is homogeneous with constant coefficients.
  The characteristic equation is $r^3=3r^2-3r+1$, with solutions
  $r_1=r_2=r_3=1$.  Since the root has multiplicity 1, the solution is
  of the form $(\alpha + \beta\cdot n + \gamma\cdot n^2)\cdot 1^n$,
  which is asymptotically just $\Theta(n^2)$.
\end{itemize}

\bigskip
\emph{Problem 3.}   
\begin{itemize}
  \item
  The recurrence is only defined for powers of 3, so we write $n=3^k$ and
  let $g(k) = f(3^k)$, thus getting
  $$g(k) = 3g(k-1) + (3^k)^2 = g(k) = 3g(k-1) + 9^k$$
  $g(k)$ has a homogeneous part with a single root of $3$, so the
  homogeneous solution is of the form $3^k$.  The driving function is
  a simple exponential with radix 9; 9 has multiplicity 0 as a root of the
  characteristic equation (i.e., it is not a root), so the particular
  solution just has the form $9^k$.  The particular solution thus
  dominates the homogeneous one in asymptotic terms and so we have
  $g(k) = \Theta(9^k)$ and thus also $f(n) = \Theta(n^2)$.
  \item
  The recurrence is only defined for powers of 2, so we write $n=2^k$ and
  let $g(k) = f(2^k)$, thus getting
  $$g(k) = 2g(k-1) - g(k-2) + (\log 2^k)^2$$
  The homogeneous recurrence is of second order and has roots $r_1=r_2=1$,
  so that the homogeneous solution is of the form $(\alpha + \beta k)\cdot 1^k$,
  just $\Theta(k)$. The driving function is a bit nastier; let us assume
  that the log is $\log_2$ to simplify matters, in which case we get
  just $k^2$ or, more precisely, $k^2\cdot 1^k$.  Since 1 is a double root,
  we need to raise the polynomial by 2 degrees, so the particular solution
  will be a 4th degree polynomial in $k$ and will dominate.  Hence
  we get $g(k) = \Theta(k^4)$ and thus $f(n) = \Theta(\log^4 n)$.
\end{itemize}
\end{document}
