\documentclass[11pt]{article}


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

\begin{document}

\title{{\bf Class work: Analysis warmup}} 

\date{}

\maketitle

Note: As usual, we denote the size of $A$ by $n$. 


\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}

}}



\fbox{
\parbox{15cm}{

\begin{codebox}
  \Procname{  $\proc{Selection-Sort}(A)$}
  \li    For $i \gets 0$ \To  n-2    \Do 
       \li    $k \gets$ the index of the smallest element among
       $A[i],A[i+1], ...,A[n-1]$
       \li swap $A[i]$ with $A[k]$
  \End
\end{codebox}

}}




\fbox{
  \parbox{9.5cm}{
    
\begin{codebox}
  \Procname{$\proc{INSERTION-SOR}T(A)$}
  \li For $k \gets 1$ \To $n-1$ \Do
  \li  $key \gets A[k]$ 
  \li $i \gets k-1$ 
  \li \While  $i \ge 0$ and $A[i]>key$  \Do
  \li  $A[i+1]=A[i]$ 
  \li  $i=i-1$ 
  \End
  \li $A[i+1]=key$ 
  \End
\end{codebox}
}}



Analyse the best-case and worst-case running time for each of the
sorting algorithms above.  Give examples of inputs that trigger
best-case and worst-case behavior, respectively.




\end{document}

