\documentclass[11pt]{article}
\usepackage[colorlinks=true]{hyperref}
\usepackage{fullpage}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage[linesnumbered,lined]{algorithm2e}
\makeatletter
\renewcommand{\@algocf@capt@plain}{above}% formerly {bottom}
\makeatother
\usepackage{scrextend}
\usepackage{enumitem}
\usepackage{float}
\setlist[enumerate]{listparindent=\parindent}
\usepackage{cleveref}%[nameinlink]
\crefname{lemma}{Lemma}{Lemmas}
\crefname{proposition}{Proposition}{Propositions}
\crefname{definition}{Definition}{Definitions}
\crefname{theorem}{Theorem}{Theorems}
\crefname{conjecture}{Conjecture}{Conjectures}
\crefname{corollary}{Corollary}{Corollaries}
\crefname{section}{Section}{Sections}
\crefname{appendix}{Appendix}{Appendices}
\crefname{figure}{Fig.}{Figs.}
\crefname{equation}{Eq.}{Eqs.}
\crefname{table}{Table}{Tables}
\crefname{algocf}{Algorithm}{Algorithms}
\title{CS302 - Problem Set 3\\\small{Due: Monday, Oct 2. Must be uploaded to Canvas before the beginning of class.}}
\author{}
\date{}
\parindent=.25in
\begin{document}
\maketitle
\vspace{-1.5cm}
Please be familiar with the sections of the syllabus on problem sets and honor code before starting this homework.
You may also want to look at the grading rubrics.
\begin{enumerate}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item \textit{3-D Closest Points Continued} \textbf{[6 points]}
~\\In this problem, you will analyze the runtime of the
algorithm for \texttt{CP\textunderscore 3D} from last week's problem set. Use
recurrence relations and a proof similar to our proof of the master method to
argue that the runtime of of the algorithm on $n$ points is $O(n\log^2 n)$.
(Recall $\log^2n=(\log n)^2$.) You may assume that the asymptotic runtime of
\texttt{CP\textunderscore Almost2D} on a set of $n$ points is $O(n\log n)$
{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item \textit{Master Method} \textbf{[6 points]}~\\ When solving divide and
conquer algorithms, things can get messy when the input size $n$ is not a
power of $b$, where $n/b$ is the size of the subproblems solved by the
recursive calls. Our in-class proof of the master method assumed that $n$ is a
power of $b$. In this problem, you will show that this assumption can be
dropped. Argue that the master method gives the same asymptotic scaling
whether the problem size is $n=b^k$, or $n'=b^{k+1}$. This result shows that if our
input is not originally a power of $b$, we can increase the size of the input
(for example, by padding with zeros) to the next largest power of $b$ without
affecting the complexity of the algorithm.
{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item \textit{More Master Method}
Suppose you have devised three different divide and conquer algorithms to solve the same problem:
\begin{itemize}
\item Algorithm I: Divides the problem into three subproblems that are each a quarter of the size of the original problem. It uses linear time to combine the solutions to the subproblems.
\item Algorithm II: Divides the problem into 2 subproblems that are each 2/3 the size of the original problem. It uses constant time to combine the solutions to the subproblems.
\item Algorithm III: Divides the problem into 9 subproblems that are each a third the size of the original problem. It uses quadratic time to combine the solutions to the subproblems.
\end{itemize}
\begin{enumerate}
\item \textbf{[6 points]} For each algorithm, give the asymptotic complexity using big-O notation.
\item \textbf{[6 points]} State which of the algorithms you would use to solve an instance of this problem.
\end{enumerate}
{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item \textit{QuickSort}~\\
Most of you should have covered QuickSort in 201. If you've forgotten, please review your notes. Try not to look at pseudocode - if you do, take some time in between looking at it and trying to recreate it yourself. You may find it helpful to work back and forth between creating the proofs and writing the pseudocode. Also, feel free to be a bit looser with your pseudocode. Use more English if that is easier. For example, writing ``swap two elements of an array'' is simpler than giving the mathematical description with a temporary value, etc.
\begin{enumerate}
\item \textbf{[9 points]} Write pseudo-code for \texttt{Partition}.
\item \textbf{[11 points]} Prove using a loop invariant that your algorithm for \texttt{Partition} is correct.
\item \textbf{[0 points - do this if you need the practice]} Write pseudo-code for \texttt{QuickSort} using your \texttt{Partition} subroutine. Please make the pivot the first element of the part of the array in question.
\item \textbf{[0 points - do this if you need the practice]} Prove your algorithm for \texttt{QuickSort} is correct.
\end{enumerate}
{}
\end{enumerate}
\end{document}