\documentclass[11pt]{article}


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

\begin{document}

\title{{\bf Class work: Insertion-sort}} \date{}

\maketitle



Insertion-sort works similarly with sorting a deck of cards. The
algorithm is described below.

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

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


}}

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

\item For a given value of $k$, describe in a brief sentence what does
  the inner while loop do.  Be as concise as you can.

\item For a given value of $k$, how many times does the while loop
  run, in the best case? 


\item What about the worst-case?

\item Give a best-case and worst-case input for insertion-sort (you
  can assume $n=7$).

\end{enumerate}


\end{document}

