\documentclass[11pt]{article}


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

\begin{document}

\title{{\bf Class work: Bubble-sort}} 

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

}}


\begin{enumerate}
\item Show how this works on $A= (3,1,5,7,4,6,2)$. 

\item What can you say about the last element in $A$ after one bubble
  pass? 

\item What happens after two bubble passes? 

\item Using this insight, argue that that algorithm is correct (argue
  that after $n-1$ bubble passes the input is always sorted).

\item Give an array $A$ that needs precisely $n-1$ bubble passes
  (where $n$ is the size of $A$). 


\end{enumerate}


\end{document}

