\input{template}
\input{macros}

\usepackage{color, graphicx}
\usepackage{amssymb, amsmath}
\usepackage{epsfig}

\begin{document}
\lecture{18}{Review of graph algorithms (contd.)}{Vipul Shingde}



\section{Recap of previous lecture}
In previous lectures we studied following definitions and theorem:
\begin{Def}
A path is alternating w.r.t. a matching $M$ if its edges alternate between those in $M$ and those not in $M$.
\end{Def}

\begin{Def}
An augmenting path is an alternating path that starts from and ends on free (unmatched) vertices.
\end{Def}

\begin{Thm}\label{bipartite-matching}
A matching M is maximum if and only if it does not contain any augmenting path.
\end{Thm}

\textbf{Algorithm for maximum matching:} We start with a single edge in the matching $M$. In each iteration we first find an augmenting path $P$. Then we exchange the matched and unmatched edges in $P$ to get a matching of one greater size. We keep doing this till a matching with no augmenting path is found. Theorem \ref{bipartite-matching} guarantees that this matching is maximum.

\begin{program}
\textbf{Modified BFS Algorithm}\\
An augmenting path in $G$ w.r.t. a matching $M$, is found using the following algorithm:\\\\
Let $L$ be set of unmatched vertices in $G$ w.r.t. $M$.\\
\textbf{For each} $u \in L$\\

1. Start BFS with root node $u$.\\
2. Till BFS is complete\\	
\>\>	Let BFS be currently at vertex $v$\\
\>\> 	\IF $v$ is at even depth\\
\>\>\>		The children of $v$ in the BFS tree will be unvisited vertices along unmatched edges incident on $v$.\\
\>\>	\ELSE\\	
\>\>\>		\IF $v$ is unmatched\\
\>\>\>\>		Augmenting path $u \rightarrow v$ found.\\
\>\>\>		\ELSE\\
\>\>\>\>		The child of $v$ in the BFS tree will be an unvisited vertex along the matched edge incident on $v$.
\end{program}


%Start with a vertex with no match edge incident on it.
%Do modified BFS, i.e. traverse alternately between matched and unmatched edges. The algorithm is explained in detail in the previous lecture.


\section{Proof of correctness of modified BFS algorithm}
If there exists an augmenting path $P$ from $u$, then applying modified BFS with $u$ as root node must find an augmenting path for the algorithm to be correct. In fact, the given alogrithm finds the shortest augmenting path $P$ from $u$.\\
Let $\{u_{0},u_{1},....u_{k-1}\}$ be the order of vertices in a shortest augmenting path $P$, with $u=u_{0}$ as one end-point.\\

Consider the following lemma
\begin{Lem}
The vertex $u_{i}$ will appear in the $i^{th}$ level of the BFS tree.
\end{Lem}

\begin{proof}
By induction on $i$.\\ \\
\textit{Base Case:} $i=0$\\
Trivially true from the algorithm.

\begin{program}
\textit{Inductive Step:} Assuming the induction hypothesis holds for $i=l$, consider $i=l+1$.\\
\> \IF $l = 2*m+1$\\
\>\>	Modified BFS algorithm will mark one matching edge(if any) incident on each vertex in even levels.\\
\>\>	Since $(u_{l}, u_{l+1})$ is a matched edge, $u_{l+1}$ will appear in level $l+1$ unless it has already appeared. If\\
\>\>	it has already appeared, then we can easily show that P will not be the shortest augmenting path.\\
\> \ELSE \IF $l = 2*m$\\
\>\>	Modified BFS Algorithm will mark all unmatched edges from each vertex in level $2*m$, and as all\\
\>\>	alternating paths of length 2*m have been marked $\Rightarrow$ all alternating paths starting from length\\
\>\>	$l=2*m+1$ are marked.
\end{program}
\end{proof}

\section{Time Complexity}
Consider graph $G(V,E)$ and let $|V| = n$ and $|E| = m$.\\
Time complexity\footnotetext[1]{With some modifications a better algorithm with run-time of $O(n^{3/2} * m)$ can be obtained} = Number of iterations times the time to find augmenting path in a matching.\\
Since the matching increases in size in every iteration, the number of iteration is bounded by $n$. In each iteration we may have to perform $O(n)$ searches (from unmatched vertices) before finding an augmenting path. A single run of modified BFS takes $O(m)$ time.

%\begin{align}
Hence time complexity = $O(m*n^{2})$.
%\end{align}

\begin{figure}[ht]
\centering
\includegraphics[height=3in]{lecture18vfig1}
\caption{Modified BFS on General graph}
\label{graph}
\end{figure} 

\section{Extending the algorithm for general graphs}

The above modified BFS algorithm works correctly for bipartite graphs. For general graphs(which can contain odd cycles), the algorithm needs to be modified. Non-bipartite graphs can contain even-even edges(as shown in the figure above). Hence if we apply modified BFS on non-bipartite graphs, it might be possible that the alogrithm might not find an augmenting path. Such an example is shown in the Fig. \ref{graph}. The augmenting path is shown in dark.\\
A solution to this problem is to shrink the odd-cycles to a vertex. This approach will be discussed in detail in next lecture.
\end{document}
