\documentclass[10pt]{article}
\usepackage{times,graphicx,epstopdf,fancyhdr,amsfonts,amsthm,amsmath,url,algorithm,algorithmic,xspace}
\usepackage[left=.75in,top=.75in,right=.75in,bottom=.75in]{geometry}
%\usepackage{tweaklist} % to tweak list spacings


\textwidth 7in
\textheight 9.5in

\pagestyle{fancy}

\begin{document}

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

%\renewcommand{\itemhook}{\setlength{\topsep}{5pt}%
 %\setlength{\itemsep}{0pt}}

% Comment out for single spacing
%\baselineskip 20pt

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

\noindent You may work with a partner on this problem set.  You need only turn in one solution.  The multi-part problem has some challenging parts.  Please start early.

\begin{question}
Given an undirected, bipartite graph $G=(V,E)$ where $V=L \cup R$ and all edges have exactly one endpoint in $L$, let $M$ be a matching in $G$.  We say that a simple path $P$ in $G$ is an {\em augmenting path} with respect to $M$ if it starts at an unmatched vertex in $L$, ends at an unmatched vertex in $R$, and its edges belong alternately to $E \setminus M$ and $M$.  (This definition of an augmenting path mimics the idea of an augmenting path a flow network corresponding to the bipartite graph.)  In this problem, we treat a path as a sequence of edges, rather than as a sequence of vertices.  A shortest augmenting path with respect to a matching $M$ is an augmenting path with a minimum number of edges.

Given two sets $A$ and $B$, the {\em symmetric difference} $A \oplus B$ is defined as $(A \setminus B) \cup (B \setminus A)$, that is, the elements that are in exactly one of the two sets.

\begin{itemize}
	\item [(a)] Show that if $M$ is a matching and $P$ is an augmenting path with respect to $M$, then the symmetric difference $M \oplus P$ is a matching and $| M \oplus P | = |M| +1$.  Show that if $P_{1}, P_{2}, \ldots, P_{k}$ are vertex-disjoint augmenting paths with respect to $M$, then the symmetric difference $M \oplus (P_{1} \cup P_{2} \cup \cdots \cup P_{k})$ is a matching with cardinality $|M| + k$.
		  
\end{itemize}

The general structure of our algorithm is the following:

\begin{algorithm}[h!] 
\caption{$\mbox{\mbox{Hopcroft-Karp}}(G)$} \label{alg:hk} 
\begin{algorithmic}[1] 
\REQUIRE A bipartite graph $G$
\medskip 
\STATE $M \leftarrow \emptyset$
\REPEAT
\STATE $\mathcal{P} \leftarrow \{P_{1}, P_{2}, \ldots, P_{k}\}$ be a {\em maximal} set of vertex-disjoint shortest augmenting paths with respect to $M$
\STATE $M \leftarrow M \oplus \{P_{1} \cup P_{2} \cup \cdots \cup P_{k}\}$
\UNTIL{$\mathcal{P} = \emptyset$}
\RETURN $M$
\end{algorithmic}
\end{algorithm}

Note that a {\em maximal} set is one that cannot be extended, so a {\em maximal} set of vertex-disjoint shortest augmenting paths with respect to $M$ is one in which there are no more augmenting paths which can be added to $M$ and keep it vertex-disjoint.  The remainder of this problem asks you to analyze the number of iterations in the algorithm (that is, the number of iterations in the {\bf repeat} loop) and to describe an implementation of line 3.

\begin{itemize}

	\item [(b)] Given two matchings $M$ and $M^{*}$ in $G$, show that every vertex in the graph $G'=(V, M \oplus M^{*})$ has degree at most 2.  Conclude that $G'$ is a disjoint union of simple paths or cycles.  	  Argue that edges in each such simple path or cycle belong alternately to $M$ or $M^{*}$.  Prove that if $|M| \leq |M^{*}|$, then $M \oplus M^{*}$ contains at least $|M^{*}| - |M|$ vertex-disjoint augmenting paths with respect to $M$.
\end{itemize}

Let $l$ be the length of a shortest augmenting path with respect to a matching $M$, and let $P_{1}, P_{2}, \ldots, P_{k}$ be a maximal set of vertex-disjoint augmenting paths of length $l$ with respect to $M$.  Let $M'=M \oplus (P_{1} \cup P_{2} \cup \cdots \cup P_{k})$, and suppose that $P$ is a shortest augmenting path with respect to $M'$.

\begin{itemize}

	\item [(c)] Show that if $P$ is vertex-disjoint from $P_{1}, P_{2}, \ldots, P_{k}$, then $P$ has more than $l$ edges. 
	
	\item [(d)] Now suppose that $P$ is not vertex-disjoint from $P_{1}, P_{2}, \ldots, P_{k}$.  Let $A$ be the set of edges $(M \oplus M') \oplus P$.  Show that $A=(P_{1} \cup P_{2} \cup \cdots \cup P_{k}) \oplus P$ and that $|A| \geq (k+1)l$.   Finally, show that $P$ has more than $l$ edges by arguing that $P$ must not only share a node with $P_{1}, P_{2}, \ldots, P_{k}$, but, in fact, an edge.	
	
	\item [(e)] Prove that if a shortest augmenting path for $M$ has length $l$, the size of the maximum matching is at most $|M| + |V|/(l+1)$.
		
	\item [(f)] Show that the number of {\bf repeat} loop iterations in the algorithm is at most $2 \sqrt{n}$.  ({\em Hint:}  By how much can $M$ grow after iteration number $\sqrt{n}$?)
		
	\item [(g)] Give an algorithm that runs in $O(m)$ time to find a maximal set of vertex-disjoint shortest augmenting paths $P_{1}, P_{2}, \ldots, P_{k}$ for a given matching $M$.  As a hint, think about a breadth-first search that labels each node as either EVEN or ODD depending on when it is encountered.  Conclude that the total running time of {\sc Hopcroft-Karp} is $O(\sqrt{n}m)$.  
		
\end{itemize}


\end{question}

\begin{question}[extra-credit]
Implement Hopcraft-Karp and show empirically that it runs in $O(\sqrt{n}m)$ time.
\end{question}

\end{document}