\documentclass[12pt,oneside]{article}

\usepackage{amsmath}
\usepackage{booktabs}
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage{enumitem}
\usepackage{fancyvrb}

%% comment out if you don't have MinionPro installed!
\usepackage[onlytext]{MinionPro}


\def\compare{ {\mathrm{compare}} }
\def\swap{ {\mathrm{swap}} }
\def\sort{ {\mathrm{sort}} }
\def\true{ {\mathrm{true}} }
\def\false{ {\mathrm{false}} }


%% \setlength{\topmargin}{-0.75in}
%% \addtolength{\textheight}{2.00in}
%% \setlength{\parindent}{0in}
\pagestyle{empty}

\begin{document}

\begin{center}
{\Large Lecture 05 Ticket}\hfill\emph{COSC 311: Algorithms}, Fall 2022
\end{center}

\vspace{0.25in}

\begin{minipage}{0.75\textwidth}
  \noindent{\large Name:}\ \hrulefill
  
\vspace{0.375in}

\end{minipage}

\noindent Consider the following method that takes two arrays of numerical values, $a$ and $b$ as input and returns another array $c$:

\begin{Verbatim}[numbers=left]
Merge(a, b):
  i, j, k <- 1
  c <- new array of size size(a) + size(b)
  while i <= size(a) and j <= size(b) do
    if a[i] <= b[j] then
      min <- a[i]
      i <- i + 1
    else
      min <- b[j]
      j <- j + 1
    endif
    c[k] <- min
    k <- k + 1
  endwhile
  
  while i <= size(a) do
    c[k] <- a[i]
    i <- i + 1
    k <- k + 1
  endwhile
  
  while j <= size(b) do
    c[k] <- b[j]
    j <- j + 1
    k <- k + 1
  endwhile

  return c
\end{Verbatim}

\noindent Argue that if $a$ and $b$ are sorted, then the array $c$ returned by  $\mathrm{Merge}(a, b)$ is sorted and contains every element from both $a$ and $b$. Your argument does not have to be too formal, but you should describe a loop invariant for the first while loop that explains *how* the procedure creates a sorted array.
\end{document}
