%\documentstyle[10pt,twoside]{article}
\documentclass[twoside]{article}
\usepackage{amsmath}
\usepackage{epsfig}
\setlength{\oddsidemargin}{0.25 in}
\setlength{\evensidemargin}{-0.25 in}
\setlength{\topmargin}{-0.6 in}
\setlength{\textwidth}{6.5 in}
\setlength{\textheight}{8.5 in}
\setlength{\headsep}{0.75 in}
\setlength{\parindent}{0 in}
\setlength{\parskip}{0.1 in}

%
% The following commands sets up the lecnum (lecture number)
% counter and make various numbering schemes work relative
% to the lecture number.
%
\newcounter{lecnum}
\renewcommand{\thepage}{\thelecnum-\arabic{page}}
\renewcommand{\thesection}{\thelecnum.\arabic{section}}
\renewcommand{\theequation}{\thelecnum.\arabic{equation}}
\renewcommand{\thefigure}{\thelecnum.\arabic{figure}}
\renewcommand{\thetable}{\thelecnum.\arabic{table}}

%
% The following macro is used to generate the header.
%
\newcommand{\lecture}[4]{
   \pagestyle{myheadings}
   \thispagestyle{plain}
   \newpage
   \setcounter{lecnum}{#1}
   \setcounter{page}{1}
   \noindent
   \begin{center}
   \framebox{
      \vbox{\vspace{2mm}
    \hbox to 6.28in { {\bf CMPSCI~611~~~Advanced Algorithms
                        \hfill Fall 2001} }
       \vspace{4mm}
       \hbox to 6.28in { {\Large \hfill Lecture #1: #2  \hfill} }
       \vspace{2mm}
       \hbox to 6.28in { {\it Lecturer: #3 \hfill Scribe: #4} }
      \vspace{2mm}}
   }
   \end{center}
   \markboth{Lecture #1: #2}{Lecture #1: #2}
   \vspace*{4mm}
}

%
% Convention for citations is authors' initials followed by the year.
% For example, to cite a paper by Leighton and Maggs you would type
% \cite{LM89}, and to cite a paper by Strassen you would type \cite{S69}.
% (To avoid bibliography problems, for now we redefine the \cite command.)
%
\renewcommand{\cite}[1]{[#1]}

\input{epsf}

%Use this command for a figure; it puts a figure in wherever you want it.
%usage: \fig{NUMBER}{FIGURE-SIZE}{CAPTION}{FILENAME}
\newcommand{\fig}[4]{
                        \vspace{0.2 in}
                        \setlength{\epsfxsize}{#2}
                        \centerline{\epsfbox{#4}}
                        \begin{center}
                        Figure \thelecnum.#1:~#3
                        \end{center}
        }

% Use these for theorems, lemmas, proofs, etc.
\newtheorem{theorem}{Theorem}[lecnum]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}
\newenvironment{proof}{{\bf Proof:}}{\hfill\rule{2mm}{2mm}}

% Some useful equation alignment commands, borrowed from TeX
\makeatletter
\def\eqalign#1{\,\vcenter{\openup\jot\m@th
  \ialign{\strut\hfil$\displaystyle{##}$&$\displaystyle{{}##}$\hfil
      \crcr#1\crcr}}\,}
\def\eqalignno#1{\displ@y \tabskip\@centering
  \halign to\displaywidth{\hfil$\displaystyle{##}$\tabskip\z@skip
    &$\displaystyle{{}##}$\hfil\tabskip\@centering
    &\llap{$##$}\tabskip\z@skip\crcr
    #1\crcr}}
\def\leqalignno#1{\displ@y \tabskip\@centering
  \halign to\displaywidth{\hfil$\displaystyle{##}$\tabskip\z@skip
    &$\displaystyle{{}##}$\hfil\tabskip\@centering
    &\kern-\displaywidth\rlap{$##$}\tabskip\displaywidth\crcr
    #1\crcr}}
\makeatother

\newcommand{\sizeof}[1]{ | #1 | }

% **** IF YOU WANT TO DEFINE ADDITIONAL MACROS FOR YOURSELF, PUT THEM HERE:
\newcommand{\gtt}{>\!>}
\newcommand{\ltt}{<\!<}

% Some general latex examples and examples making use of the
% macros follow.  
%**** IN GENERAL, BE BRIEF. LONG SCRIBE NOTES, NO MATTER HOW WELL WRITTEN,
%**** ARE NEVER READ BY ANYBODY.
%This lecture's notes illustrate some uses of
%various \LaTeX\ macros.  
%Take a look at this and imitate.
%
%\section{Some theorems and stuff} % Don't be this informal in your notes!
%
%We now delve right into the proof.
%
%\begin{lemma}
%This is the first lemma of the lecture.
%\end{lemma}
%
%\begin{proof}
%The proof is by induction on \ldots.
%For fun, we throw in a figure.
%%%%NOTE USAGE !
%\fig{1}{1in}{A Fun Figure}{funfig.eps}
%
%This is the end of the proof, which is marked with a little box.
%\end{proof}
%
%\subsection{A few items of note}
%
%Here is an itemized list:
%\begin{itemize}
%\item this is the first item;
%\item this is the second item.
%\end{itemize}
%
%Here is an enumerated list:
%\begin{enumerate}
%\item this is the first item;
%\item this is the second item.
%\end{enumerate}
%
%Here is an exercise:
%
%{\bf Exercise:}  Show that ${\rm P}\ne{\rm NP}$.
%
%Here is how to define things in the proper mathematical style.
%Let $f_k$ be the $AND-OR$ function, defined by
%
%\[ f_k(x_1, x_2, \ldots, x_{2^k}) = \left\{ \begin{array}{ll}
%
%       x_1 & \mbox{if $k = 0$;} \\
%
%       AND(f_{k-1}(x_1, \ldots, x_{2^{k-1}}),
%          f_{k-1}(x_{2^{k-1} + 1}, \ldots, x_{2^k}))
%        & \mbox{if $k$ is even;} \\
%
%       OR(f_{k-1}(x_1, \ldots, x_{2^{k-1}}),
%          f_{k-1}(x_{2^{k-1} + 1}, \ldots, x_{2^k}))   
%       & \mbox{otherwise.} 
%       \end{array}
%       \right. \]
%
%\begin{theorem}
%This is the first theorem.
%\end{theorem}
%
%\begin{proof}
%This is the proof of the first theorem. We show how to write pseudo-code now.
%%*** USE PSEUDO-CODE ONLY IF IT IS CLEARER THAN AN ENGLISH DESCRIPTION
%
%Consider a comparison between $x$ and~$y$:
%\begin{tabbing}
%\hspace*{.25in} \= \hspace*{.25in} \= \hspace*{.25in} \= \hspace*{.25in} \= \hspace*{.25in} \=\kill
%\>{\bf if} $x$ or $y$ or both are in $S$ {\bf then } \\
%\>\> answer accordingly \\
%\>{\bf else} \\
%\>\>    Make the element with the larger score (say $x$) win the comparison \\
%\>\> {\bf if} $F(x) + F(y) < \frac{n}{t-1}$ {\bf then} \\%
%\>\>\> $F(x) \leftarrow F(x) + F(y)$ \\
%\>\>\> $F(y) \leftarrow 0$ \\
%\>\> {\bf else}  \\
%\>\>\> $S \leftarrow S \cup \{ x \} $ \\
%\>\>\> $r \leftarrow r+1$ \\
%\>\> {\bf endif} \\
%\>{\bf endif} 
%\end{tabbing}
%
%This concludes the proof.
%\end{proof}
%
%
%\section{Next topic}
%
%Here is a citation, just for fun \cite{CW87}.
%

% **** THIS ENDS THE EXAMPLES. DON'T DELETE THE FOLLOWING LINE:


\begin{document}
%FILL IN THE RIGHT INFO.
%\lecture{**LECTURE-NUMBER**}{**DATE**}{**LECTURER**}{**SCRIBE**}
\lecture{11}{October 15, 2001}{Micah Adler}{Qi Li}

\section{Lecture Overview}
\begin{itemize}
\item{Seidel's algorithm}
\item{Network Flow Problem}
\end{itemize}

\section{Seidel's algorithm}

In this lecture, we consider the problem of finding shortest
paths between all pairs of vertices in a undirected and unweighted
graphs. Given a graph $G=(V,E)$, we shall compute  the distance 
matrix (a matrix of shortest path lengths between any node pairs).
Seidel's algorithm\cite{S92} can  solve the problem in 
$O(\mu(|V|)\log{|V|})$ time, where $\mu(|V|)$ is time required to
multiply two $n \times n$ matrices. When we use BFS,
Breadth-first Search, the running time is $O(|V|^3)$.

 

\subsection{Description of Seidel's algorithm}

Given an undirected and unweighted graph $G$, defined 
over a set of  vertices $V$ and a set of edges $E$, 
$G_2$ is the undirected and unweighted graph which is 
constructed from $G$ in the following manner: G is augmented 
by edges $(i,j)$ if $G$ has a path of length 2 from i to j.
As shown in the figure 11.1, the solid edges are from $G$, 
the dotted edges are added in $G_{2}$.

\fig{1}{2.5in}{Augmenting graph $G$ into $G_{2}$}{figa.eps}

We define £º
\begin{itemize} 
\item   [${M[G]}$:] the adjacency matrix of $G$,
\item   [${D[G]}$:] the distance matrix for graph $G$. 
\item   [${P[G]}$:] a binary matrix, where 

$$ P[ G ] (i, j) = \left\{ \begin{array}{ll}
   1 & \mbox{ if shortest path from } i \mbox{ to } j \mbox{ has odd length
} \\
   0 & \mbox{ otherwise }
   \end{array}   \right. $$
   
\end{itemize}

Seidel's algorithm is described as following:  
\begin{description}
\item[Input:]  An undirected and unweighted graph $G=(V, E)$, where $V$ is a
  set of vertices and $E$ is a set of edges. 

\vspace{2mm}
\item[Output:] [${D[G]}$] the distance matrix for graph $G$.
of the shortest path from $u$ to $v$.
\end{description}

The heart of Seidel's algorithms is the following procedure APSP, 
which, given the adjacency matrix of graph $G$, returns the
distance matrix $D[G]$ for $G$. APSP computes ${D[G]}$ in time 
$O(\mu(|V|)\log{|V|})$, if the time cost on recurrence is not
included.

$D[G]$=APSP($M[G]$)

{\bf APSP}($M[G]$): $D[G]$

\begin{tabbing}
\hspace*{.25in} \= \hspace*{.25in} \= \hspace*{.25in} \= \hspace*{.25in} \= \hspace*{.25in} \= \kill
1. \>{\bf compute} $M[G_{2}]$ \\
2. \>{\bf if} $\forall i \neq j; M[G_{2}](i,j) = 1$ \\
\>{\bf then} \\
3. \>\>{\bf return} \= $D[G](i,j) = 
\left\{
    \begin{array}{ll}
      0 & \mbox{if } i=j\\
      1 & \mbox{if } M[G](i,j)=1\\
      2 & \mbox{otherwise }
    \end{array}
\right.$\\
        %y = \left\{\begin{array}{ll}
        %       0 & \mbox{if } i = j\\
        %       1 & \mbox{if } M[G]_{i,j}=1 \\
        %       2 & \mbox{otherwise} \\
        %        \end{array}
        %       \right
      
\>{\bf else} \\
4. \>\> $D^{'}[G]= \mathit{APSP}(M[G_{2}])$ \\
5. \>\> {\bf compute} $P[G]$ \\
\>{\bf endif}\\
6 \>{\bf return} $D[G] = 2 D^{'}[G] -P[G]$
\end{tabbing}


\subsection{Proof of Correctness}
\begin{proof}
Define the diameter of a graph G is the maximum shortest path from
vertex i to vertex j($\forall i \neq j$),The proof for the correctness 
of Seidel's algorithm can be shown using induction on diameter of $G$.

{\em Base case:} diameter $\le 2$, thus $\forall i \neq j$; $M[G_{2}](i,j) = 1$,
APSP stops at step3. 


{\em Inductive Step:} Assume the algorithm is correct when diameter is 
put to $k$, now consider a undirected graph G with diameter of $k+1$.
The expression in step $6$ is true, as long as $\forall i,j; D[G](i,j) \le
k$. To any node pair $(i,j)$ in $G$, we discuss $D[G](i,j)$ in two cases:


{\bf Case 1:} if $P[G](i,j)= 0$, i.e. the path distance between $i$ 
and $j$ is even. This immediately implies, (and as is illustrated in
 the figure) that the path distance between $i$ and $j$ in $G_{2}$ 
is half of that in $G$,or
\begin{displaymath}
  D[G_{2}]_{i,j} = \frac{1}{2}D[G]_{i,j}
\end{displaymath}

Therefore $D[G]_{i,j} = 2D^{'}[G] - P[G]$

\fig{2}{3.5in}{Path of even length}{fig2a.eps}


{\bf Case 2:} if $P[G](i,j) = 1$, i.e. the path from $(i,j)$ is of 
odd length. Let this be some length $2m +1$ where $m$ is
a natural number. Then the path length to a node just before $j$ would
be $2m$, and can be actually reached in $m$ steps using the edges in
graph $G_{2}$. Hence to reach $j$ from this node, we need to take one
extra step in $G$, giving us a final path length of $m+1$.  Thus, to
generalize,

\begin{eqnarray*}
  D[G_{2}](i,j) & = & \frac{1}{2}[D[G](i,j)-1] +1   \\
  & = & \frac{1}{2}D[G](i,j)+\frac{1}{2}  \\
  & = & \frac{1}{2}[D[G](i,j)+1]  \\
\end{eqnarray*} 

and thus $D[G]_{i,j} = 2D^{'}[G] - P[G]$

\fig{3}{3.5in}{Path of odd length}{fig1a.eps}

Therefore, $D[G]_{i,j} = 2D^{'}[G] - P[G]$, Step $6$ and hence 
Seidel's algorithm is true for graphs of all diameters,


\end{proof}


\subsection{Analysis of Seidel's algorithm} 


In Step 1 and Step 5, matrix multiplication costs $O(\mu(|V|))$ time, 
we will discuss the implementation of Step 5 in the following section. 

In Step 2,3 and Step 6, searching and updating the matrix take $O(|V|^2)$ time. 

The length of diameter in $G_{2}$ is half of 
the length in original graph $G$. Since the diameter is at most $|V|$, the 
level of recurrence is O($\log{|V|}$). Clearly, When the recurrence stops, 
every connected component of G is a complete graph. 

So that the total running time is $O(\mu(|V|)\log{|V|})$.



\subsection{Computing P[G]}

Now we provide an efficient method to compute the parity matrix $P[G]$ in 
$O(\mu(|V|))$ time.

\textbf{Claim:} Define $X = D'[G] \cdot M[G]$, $X$ is the product of
$D'[G]$ and $M[G]$.  $D'[G]$ is the distance matrix of $G_{2}$. We
have the following claim:

\begin{displaymath}
  P[G](i,j) = 0 \Longleftrightarrow X(i,j) \ge D'[G](i,j) \cdot
  \mathit{degree}_{[G]}(j)
\end{displaymath}

where, $\mathit{degree}_{[G]}(j)$ is the number of edges that are
incident to node $j$ in graph $G$.


\begin{proof}
  In order to prove this claim, we need to show that both directions of
  the implication are true.  Thus we can break down the proof in two
  parts:
  
  \begin{itemize}
  \item $P[G]_{(i,j)} = 0  \Longrightarrow X_{(i,j)} \ge  D'[G]_{(i,j)} 
        \cdot degree_{[G]}(j)$
       
  \item $P[G]_{(i,j)} = 1 \Longrightarrow X_{(i,j)} 
            < D'[G]_{(i,j)}\cdot degree_{[G]}(j)$
  \end{itemize}
  
    The matrix $X$ is computed in the following form: 
    \begin{eqnarray*}
      X_{(i,j)} & = & \sum_{k=1}^{|V|}(D'[G]_{(i,k)} \cdot
      M[G]_{(k,j)} ) \\
      & = & \sum_{k \in Adj_{[G]}(j)} (D'[G]_{(i,k)})
    \end{eqnarray*} 
    
    From this representation it is apparent that $X(i,j)$ is the sum of
    $degree_{[G]}(j)$ terms.  
    
    First, we prove that $P[G]_{(i,j)} = 0 \Longrightarrow X_{(i,j)} \ge 
      D'[G]_{(i,j)} \cdot degree_{[G]}(j)$
    
    
    Consider if  each of these terms
    is in turn greater than $D^{'}[G]_{(i,j)}$, then their sum would
    be greater than $D'[G]_{(i,j)} \cdot degree_{[G]}(j)$. Hence we
    only need to prove that if $P[G]_{(i,j)} = 0$, then
    \begin{displaymath}
      \forall k \in Adj_{[G]}(j), D'[G]_{(i,k)} \ge
      D'[G]_{(i,j)}
    \end{displaymath}
          
  
  We will look at two cases:\\
  \textbf{Case 1:} $k$ is on the shortest path from $i$ to $j$, which is
  shown in the following diagram as $k_0$. It is apparent that the length of the path
  from $i$ to $j$ is equal to that of the path from $i$ to $k$.
  
  \textbf{Case 2:} $k$ is not on any shortest path from $i$ to $j$.
  such as $k_1$ in the following diagram, we can see that, since the number of
  edges between $i$ and $j$ is even, and $k$ is adjacent to $j$,
  it would take at least one more step to reach $k$, hence the path
  from $i$ to $k$ is longer.

  
  \begin {figure}
  \begin{center}
 \epsfig{file=fig1.eps, scale=0.5}
 \caption{An example for $P[G]_(i,j)=0$}
  \end{center}
  \end{figure}
 
 
   
  Thus, if $P[G]_{(i,j)} = 0$, then
  \begin{displaymath}
      X_{(i,j)}  =  
       \sum_{k \in Adj_{[G]}(j)} (D'[G]_{(i,k)})
       \ge D'[G]_{(i,j)} \cdot degree_{[G]}(j)
    \end{displaymath} 
  Therefore, $P[G]_{(i,j)} = 0 \Longrightarrow X_{(i,j)} \ge 
      D'[G]_{(i,j)} \cdot degree_{[G]}(j)$
  
   
  Second , we prove that:$P[G]_{(i,j)} = 1 \Longrightarrow X_{(i,j)} 
            < D'[G]_{(i,j)}\cdot degree_{[G]}(j)$
  
  We just need to prove that if $P[G]_{(i,j)} = 1$, then 
   \begin{displaymath}
   \forall k\in Adj_{[G]}(j),
   D'[G]_{(i,k)} \le D'[G]_{(i,j)}
    \end{displaymath}
   and \begin{displaymath}
   \exists k\in Adj_{[G]}(j), D'[G]_{(i,k)} <
      D'[G]_{(i,j)}
    \end{displaymath}
    
    We shall still look at two cases:\\
   \textbf{Case 1:} $k$ is on the shortest path(as $k_0$ in the above figure
   We can easily see from the graph that $D'[G]_{(i,k)} < D'[G]_{(i,j)}$ since 
   it can be reached directly using edges in $G_{2}$, while we need to take an 
   extra step to go to $j$, so that $D'[G]_{(i,k_0)} < D'[G]_{(i,j)}$

    \textbf{Case 2:} $k$ is not on the shortest path (as $k_1$ in the above
    figure. Because the length between $i$ and $j$ is odd, in order to
    reach $j$ we can use the edges from $G_{2}$ only till a node before
    $j$ and then we must take an extra step on an edge in $G$. While, to
    reach $k$ we can jump from this previous node to $k$ using a $G_{2}$
    edge directly. Hence the path lengths are equal. 


\begin {figure}
  \begin{center}
 \epsfig{file=fig3.eps, scale=0.5}
 \caption{An example for $P[G]_(i,j)=1$}
  \end{center}
  \end{figure}
  
  Because there must exist a node $k_0\in Adj_{[G]}(j)$ on the shortest path from
  i to j, so that when $P[G]_{(i,j)} = 1$, then
  \begin{displaymath}
      X_{(i,j)}  =  
       \sum_{k \in Adj_{[G]}(j)} (D'[G]_{(i,k)})
       < D'[G]_{(i,j)} \cdot degree_{[G]}(j)
    \end{displaymath} 
  
  Then , $P[G]_{(i,j)} = 1 \Longrightarrow X_{(i,j)} 
            < D'[G]_{(i,j)}\cdot degree_{[G]}(j)$
  
\end{proof}



\section{Network Flow}
We now look at a class of problems under the general heading of 
Network Flow. The following graph is an example of a flow network.  It
shows the capacity of each edge and the values (in parentheses) of a
sample flow.

\subsection{ Description of Network Flow}
\fig{6}{5.5in}{Example for a flow network}{fig5.ps}

{\bf Input:}
\begin{itemize} 
\item Directed Graph \(G\),$G=$($V$,$E$).
\item \begin{tabbing} Capacities: \=$C(u,v) > 0$ for $(u,v) \in E$\\
                                \>$C(u,v) = 0$ for $(u,v) \notin E$ \\
                          \end{tabbing}
\item A source node \(s\),a sink node $t$

\end{itemize}

{\bf Output:} The maximum flow from \(s\) to \(t\) with the flow
function \(f:V\times V \rightarrow \Re\)
and the following properties:

\begin{enumerate}
\item Skew-symmetry: \(f(u,v) = -f(v,u) \hspace{2ex} \forall u,v \in V\)
\item Conservation of Flow: 
      \(\sum{f(u,v) = 0} \hspace{2ex} \forall u,v \in (V - \{s,t\}) \)
\item \begin{tabbing} Capacity Constraints: \= $f(u,v) \leq c(u,v) \hspace{2ex} \forall u,v \in V$ \\
                                            \> $c(u,v) = 0\ \ if\ (u,v) \notin E$ \\
\end{tabbing}
\end{enumerate}

We define the size of a flow as the total flow coming out of the source:
\[\begin{split} \vert f \vert & = \sum_{v}{f(s,v)} \\
                              & = \sum_{v}{f(v,t)} \end{split}
\]

\subsection{The $s\!\!-\!\!t$ cut}
Define an $s\!\!-\!\!t$ cut (abbreviated cut) of $G$ is a partition of the
vertices $v$ into two sets $A$ and $B$ such that $s \in A$ and $t \in
B$. 

\fig{7}{2in}{An example $s\!\!-\!\!t$ cut}{fig11.eps}

The capacity of cut $(A,B)$ is defined as the sum of the capacities of
all edges across the cut:
\[c(A,B) = \sum_{u \in A,v \in B}{c(u,v)} \]
The flow across a cut is defined similarly, as the flow across all
edges across the cut:
\[f(A,B) = \sum_{u \in A,v \in B}{f(u,v)} \]

The capacity constraints still hold when talking about cuts, so we
can say that $f(A,B) \leq c(A,B)$.

\begin{claim}
For any flow $f$ and for all cuts $(A,B)$, $f(A,B) = \vert f \vert$
\end{claim}

\begin{proof}by induction on the size of $A$.\\

{\bf Base Case: } $\vert A \vert = 1$ ( $A = \{ s \}$ ) \\
In this case, the claim follows from the definition of the size of a
flow.

{\bf Inductive Step: } We assume that $f(A,B) = \vert f \vert
\hspace{2ex} \forall A$ such that $\vert A \vert \leq k$. In next
lecture, we will show that it holds $\forall A$ such that $\vert A \vert
= k + 1$.\end{proof}

\section*{References}

\begin{itemize}
\item[S92] {\sc R.~Seidel},{\ On the All-Pairs-Shortest-Path Problem in Unweighted Undirected Graphs},
{\it Journal of Computer and System Sciences \/~\bf 51}, 1995, ~pp. 400--403.
\item[CLR] {\sc T.~Cormen} and {\sc C.~Leiserson} and {\sc R.~Rivest},
Introduction to Algorithms, MIT Press, 1990
\item[SN10] {\sc Honggang ~Zhang} and {\sc S.~Jaiswal} Scribe notes for
lecture 10 of Computer Science 611, University of Massachusetts at
Amherst, 2000.
\item[SN11] {\sc M.~Billmers} and {\sc Wei ~Li} Scribe notes for
lecture 11 of Computer Science 611, University of Massachusetts at
Amherst, 2000.

\end{itemize}
\end{document}
















