\documentclass[10pt]{article}

\usepackage{times,graphicx,epstopdf,fancyhdr,amsfonts,amsthm,amsmath,algorithm,algorithmic,xspace,hyperref}
\usepackage[left=1in,top=1in,right=1in,bottom=1in]{geometry}

%\textwidth 7in
%\textheight 9.5in


\pagestyle{fancy}



\lhead{Williams College}
\chead{Homework 1}
\rhead{Brent Heeringa}
\cfoot{Algorithm Design and Analysis - CS 256}
\rfoot{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\headwidth}{\textwidth}
%\renewcommand{\footwidth}{\textwidth}
%\addtolength{\headwidth}{\marginparwidth}
%\addtolength{\headwidth}{\marginparsep}
\renewcommand{\footrulewidth}{0.4pt}

\newtheorem{claim}{Claim}
\newtheorem{definition}{Definition}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{observation}{Observation}
\newtheorem{question}{Question}

\begin{document}
	
Here is the first homework.  It has several questions that warrant proofs.  Try to emulate the proof style that we have used in class and the proof style that appears in the text.  That is, make sure your reasoning flows logically from one statement to another.  You should edit your proofs to make sure they read well.  Abstraction is crucial.  That is, identify and isolate common ideas.  Write clearly and concisely or use \LaTeX  \ to typeset your solutions.  Ask for help if you need it.  Have fun!

\begin{question}
Take the following list of functions and arrange them in ascending order of growth rate.  That is, if function $g(n)$ immediately follows function $f(n)$ in your list, then it should be the case that $f(n)$ is $O(g(n))$.  Please prove your claims.
\begin{enumerate}
\item $f_{1}(n) = 2^{\sqrt{(\log n)}}$
\item $f_{2}(n)=2^{n}$
\item $f_{3}(n)=n^{4/3} = 2^{4/3 \log n}$
\item $f_{4}(n)=n(\log n)^{3}$
\item $f_{5}(n)=n^{\log n} = 2^{(\log n )^{2}}$
\item $f_{6}(n)=2^{2^{n}}$
\item $f_{7}(n)=2^{n^{2}}$
\end{enumerate}
\end{question}

\begin{question}
Decide whether you think the following statements are true or false.  If a statement is true, give a short explanation why it's the case.  If it's false, give a counterexample.
\begin{description}
	\item [(a)] In every instance of the Stable Matching Problem there is a stable matching containing a pair $(m,w)$ such that $m$ is ranked first on the preference list of $w$ and $w$ is ranked first on the preference list of $m$.\\
		
	\item [(b)] Consider an instance of the Stable Matching Problem in which there exists a man $m$ and a woman $w$ such that $m$ is ranked first on the preference list of $w$ and $w$ is ranked first on the preference list of $m$.  Then the pair $(m,w)$ belongs to every possible stable marriage for this instance. \\
		
\end{description}
\end{question}


\begin{question}
Consider the following problem called the {\em Stable Roommate Problem}.  There are $2n$ people, each of whom ranks the other $2n-1$ people in order of cohabitation preference.  For example, Alice, Bob, Carlos, and Don might have the following rankings:

\begin{table}[h]
\begin{center}
\begin{tabular}{r|ccc}
Name & \multicolumn{3}{c}{Preference}\\
\hline
Alice & Bob & Carlos & Don\\
Bob & Alice & Carlos & Don \\
Carlos & Don & Alice & Bob \\
Don & Carlos & Alice & Bob
\end{tabular}
\end{center}
\end{table}

The goal is to find a stable matching ({\em i.e.,} $n$ pairs of roommates such that no two people prefer each other to their current roommate).  We saw in class that a stable matching always exists for instances of the stable matching problem.  Do stable matchings always exist for the stable roommate problem?  If so, provide a proof.  If not, give a counterexample.
\end{question}

\begin{question}
Consider the problem of finding the largest product subinterval in a sequence of integers.  For example, given $(10,-1,5,6)$ the largest product subinterval has value 30 and corresponds to the interval $[2,3]$.  Give an algorithm that solves the largest product subinterval problem.  Analyze your solution and give an upper bound on its running time.
\end{question}

\pagebreak

\begin{question}[Algorithms in the wild] \label{q:wild}
The National Residency Matching Program (NRMP) matches medical students with residency programs.  Here is what the NRMP says on their website:
\begin{quote}
The NRMP Main Match provides an impartial venue for matching applicants' preferences for residency positions with program directors' preferences for applicants. Each year approximately 16,000 U.S. allopathic medical school seniors and 15,000 graduates of osteopathic, Canadian or foreign medical schools compete for approximately 24,000 residency positions.
\end{quote}
In this matching problem, there are $n$ students and $m$ hospitals.  Each hospital $h_{i}$ has $p_{i}$ available positions.  Each student ranks the $m$ hospitals and each hospital ranks the $n$ students.  Since there are more students than total positions available, we assume that $n > \sum_{i=1}^{m} p_{i}$.  Thus, some students are never matched.   As a result, we need a slightly expanded version of stability.  As before, the matching is unstable if 
	\begin{itemize}
		\item $s$ is assigned to $h$ and $s'$ is is assigned to $h'$ but $s$ prefers $h'$ to $h$ and $h'$ prefers $s$ to $s'$.  
	\end{itemize}
But it is also unstable if 
	\begin{itemize}
		\item $s$ is assigned to $h$ and $s'$ is not assigned to a hospital but $h$ prefers $s'$ to $s$.
	\end{itemize}
Give an algorithm to find a stable matching of students to hospitals where every hospital position is filled with a student.  Show that your algorithm is correct and that it runs in time polynomial in $n$ and $m$.  Your algorithm description and analysis should be clear and concise.  
\end{question}

\begin{question}[Extra credit]
Implement your algorithm from Question~\ref{q:wild} in a programming language of your choice.  Your program should take two files {\tt sranks} and {\tt hranks} as input.  The file {\tt sranks} is a ranking of hospitals for each student.  The format of the file is
\begin{verbatim}
student name1,hos_rank1,hos_rank2, ...,hos_rankm
student name2,hos_rank1,hos_rank2, ...,hos_rankm
.
.
\end{verbatim}
The file {\tt hranks} is a ranking of students for each hospital.  The format of the file is 
\begin{verbatim}
hospital name1,numslots,stu_rank1, stu_rank2, ..., stu_rankn
hospital name2,numslots,stu_rank1, stu_rank2, ..., stu_rankn
.
.
\end{verbatim}
where {\tt numslots} is the number of available slots for that hospital.  The output should be a stable matching of students to hospitals.  The format of the output should be 
\begin{verbatim}
hospital1,student1,student2,...
hospital2,student1,student2,...
.
.
\end{verbatim}
where each hospital is assigned the appropriate number of students.  Run your program on the {\tt sranks} and {\tt hranks} files linked on the course website and use {\tt turnin} to turn in your properly formatted output file.  Please do not submit anything but the output file containing the matching.
\end{question}


\begin{question}
I found this assignment:
\begin{enumerate}
	\item Awful.  This assignment sucks big rocks through a small straw.
	\item Easy.  My cat could do it.
	\item Fun, but somewhat challenging.  I thought about it every now and then on a walk.
	\item Impenetrable.  Geez Brent, cut me some slack!
\end{enumerate}
\end{question}

\end{document}
