\documentclass[12pt,oneside]{article}

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

%% 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}} }
\def\split{ {\mathrm{split}} }
\def\val{ {\mathrm{val}} }



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

\begin{document}

\begin{center}
{\Large Lecture 12 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 In class we saw the "Master Theorem" for solving recurrences:

\noindent\textbf{Master Theorem.} Suppose the running time $T(n)$ of a (recursively defined) method satisfies $T(n) = a T(n / b) + f(n)$. Define $c = \log_b a$. Then:

\begin{enumerate}
\item If $f(n) = O(n^d)$ for $d < c$ then $T(n) = O(n^c)$.
\item If $f(n) = \Theta(n^c \log^k n)$ then $T(n) = O(n^c \log^{k+1} n)$.
\item If $f(n) = \Omega(n^d)$ for $d > c$, then $T(n) = O(f(n))$.
\end{enumerate}

\noindent For the following methods, apply the Master Theorem to derive a bound on the running time of the method. In particular, for each method you should compute the values $a, b, c,$ and the function $f$ to determine which (if any) of the three conditions above apply. In both cases, the size $n$ of the input is $n = j - i$.

\begin{enumerate}
\item \textbf{Binary Search.}
\begin{verbatim}
BinarySearch(a, val, i, j):
  if j = i then return false
  if j - i = 1 then return a[i] = val
  m <- (j + i) / 2
  if a[m] > val then
    return BinarySearch(a, val, i, m)
  else
    return BinarySearch(a, val, m, j)
  endif  
\end{verbatim}
\item \textbf{Merge Sort.} Assume that the \texttt{Merge} procedure runs in time $O(n)$.
\begin{verbatim}
MergeSort(a, i, j):
  if j - i = 1 then
    return
  endif
  m <- (i + j) / 2
  MergeSort(a,i,m)
  MergeSort(a,m,j)
  Merge(a,i,m,j)  
\end{verbatim}
\end{enumerate}

\end{document}
