\documentclass[11pt]{article}

\usepackage{fullpage}
\usepackage{graphicx}
\usepackage{clrscode3e}




\begin{document}

\title{Algorithms Lab 2}

\date{}
\maketitle



The in-lab problems are to be solved during the lab time.  Work with
your team, but write your solutions individually. You do not need to
turn in your answers, only discuss them with me. Ask me for feedback
on how you write your answers as well.

The homework problem set is due in one week. Work with your team, but
write your solutions individually. List the people with whom you
discussed the problems.


\vspace{1cm}
\section{ In lab exercises}



\begin{enumerate} 

\item Finish/review the exercises from class, which you can also find
  on the class website.

\item Find a simple formula for $\sum_{k=1}^{n} (2k-1)$. 

\item (CLRS 3-4.a) Prove or disprove:   $f = O(g)$ implies that $g = O(f)$. 

\item  Prove or disprove:   $f = O(g)$ implies that $g = \Omega(f)$. 


\end{enumerate}


\vspace{1cm}
\section{Homework problems}

Your assignment will be evaluated based not only on the final answer, but 
also on clarity, neatness and attention to details. For example, you'll 
want to leave plenty of space in between problems so that we can give you 
feedback. 

\begin{enumerate} 

\item Consider the folowing code for BubbleSort that we discussed in
  class: 



\fbox{
\parbox{9.5cm}{

\begin{codebox}
  \Procname{  $\proc{Bubble-Sort}(A)$}
  \li    For $k \gets 1$ \To $n-1$    \Do 
  \li     \Comment{do a bubble pass}
       \li  For  $i \gets 0$ \To $n-2$  \Do 
            \li if $A[i] > A[i+1]$: swap 
  \End
  \End
  
\end{codebox}

}}

(a) Give the best-case and worst-case running time of the
  algorithm. Express them as $\Theta()$ bounds and give a brief
  justification.

  (b) Show how to change the code so that the algorithm dos not do any
  redundant bubble-passes (i.e. if the input needs only 3 bubble
  passes to be sorted, the algorithm does only 3 passes).


\vspace{2cm}
  Find a tight bound for the solution of the following recurrences
  using iteration.
\item $T(n) = T(n/3) + 1$

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

\item $T(n) = T(\sqrt n) + 1$

\item $T(n) = T(n-1) + n$

\item $T(n) = 7 T(n/2) + n^3$

\item $T(n) = 7 T(n/2) + n^2$

\end{enumerate}


\end{document}
%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 
