\documentclass[11pt]{article}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{graphicx}
\DeclareMathOperator*{\E}{\mathbb{E}}
\let\Pr\relax
\DeclareMathOperator*{\Pr}{\mathbb{P}}

\newcommand{\eps}{\epsilon}
\newcommand{\inprod}[1]{\left\langle #1 \right\rangle}
\newcommand{\R}{\mathbb{R}}

\newcommand{\handout}[5]{
	\noindent
	\begin{center}
		\framebox{
			\vbox{
				\hbox to 5.78in { {\bf CS 388R: Randomized Algorithms } \hfill #2 }
				\vspace{4mm}
				\hbox to 5.78in { {\Large \hfill #5  \hfill} }
				\vspace{2mm}
				\hbox to 5.78in { {\em #3 \hfill #4} }
			}
		}
	\end{center}
	\vspace*{4mm}
}

\newcommand{\lecture}[4]{\handout{#1}{#2}{#3}{Scribe: #4}{Lecture #1}}

\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{observation}[theorem]{Observation}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{fact}[theorem]{Fact}
\newtheorem{assumption}[theorem]{Assumption}

						  % 1-inch margins, from fullpage.sty by H.Partl, Version 2, Dec. 15, 1988.
\topmargin 0pt
\advance \topmargin by -\headheight
\advance \topmargin by -\headsep
\textheight 8.9in
\oddsidemargin 0pt
\evensidemargin \oddsidemargin
\marginparwidth 0.5in
\textwidth 6.5in

\parindent 0in
\parskip 1.5ex

\usepackage[]{algorithm2e}


\usepackage{filecontents}

\begin{filecontents}{references.bib}
  
@article{dijkstra1959note,
  title={A note on two problems in connexion with graphs},
  author={Dijkstra, Edsger W},
  journal={Numerische mathematik},
  volume={1},
  number={1},
  pages={269--271},
  year={1959},
  publisher={Springer}
}

@article{floyd1962algorithm,
  title={Algorithm 97: shortest path},
  author={Floyd, Robert W},
  journal={Communications of the ACM},
  volume={5},
  number={6},
  pages={345},
  year={1962},
  publisher={ACM}
}

@techreport{bellman1956routing,
  title={On a routing problem},
  author={Bellman, Richard},
  year={1956},
  institution={DTIC Document}
}

@techreport{ford1956network,
  title={Network flow theory},
  author={Ford Jr, Lester R},
  year={1956},
  institution={DTIC Document}
}


@article{strassen1969gaussian,
  title={Gaussian elimination is not optimal},
  author={Strassen, Volker},
  journal={Numerische Mathematik},
  volume={13},
  number={4},
  pages={354--356},
  year={1969},
  publisher={Springer}
}

@inproceedings{coppersmith1987matrix,
  title={Matrix multiplication via arithmetic progressions},
  author={Coppersmith, Don and Winograd, Shmuel},
  booktitle={Proceedings of the nineteenth annual ACM symposium on Theory of computing},
  pages={1--6},
  year={1987},
  organization={ACM}
}

@article{stothers2010complexity,
  title={On the complexity of matrix multiplication},
  author={Stothers, Andrew James},
  year={2010},
  publisher={The University of Edinburgh}
}


@inproceedings{williams2012multiplying,
  title={Multiplying matrices faster than Coppersmith-Winograd},
  author={Williams, Virginia Vassilevska},
  booktitle={Proceedings of the forty-fourth annual ACM symposium on Theory of computing},
  pages={887--898},
  year={2012},
  organization={ACM}
}

@book{motwani1995randomized,
  title={Randomized Algorithms},
  author={Motwani, Rajeev and Raghavan, Prabhakar},
  year={1995},
  publisher={Cambridge University Press}
}



\end{filecontents}


\begin{document}

\lecture{14 --- October 26, 2015}{Fall 2015}{Prof.\ Eric Price}{ An T. Nguyen, Adarsh Prasad}

\section{Overview}

In this lecture, we study the problem of finding shortest paths. Let $\mathbb{G}$ be a graph of $m$ edges and $n$ vertices. First let's look at some algorithms.

\begin{table}[h]
\centering

\label{tab:shortest}
\begin{tabular}{l|l|l|l}
Algorithm      & Sources   & Negative Weight & Time                   \\ \hline
Dijkstra       & Single    & No              & $O(m+ n \log n)$          \\
Floyd-Warshall & All Pairs & Yes             & $O(n^3)$ \\
Bellman-Ford   & Single    & Yes             & $O(mn)$                 
\end{tabular}

\caption{Comparison of some shortest path algorithms.}
\end{table}

The Floyd-Warshall algorithm is very simple:

\begin{algorithm}[H]
\KwData{Distance matrix $D$}
\KwResult{Shortest path matrix $D$}
\SetAlgoLined
 \For{k in $[n]$}{
  \For{i in $[n]$}{
  \For{j in $[n]$}{
    $D_{ij} = \min (D_{ij}, D_{ik} + D_{kj})$
  }}
  }
 
 \caption{Floyd-Warshall algorithm}
\end{algorithm}

\section{Faster algorithm using matrix multiplication}

We can have faster algorithms for all pair shortest paths in $O(MM(n))$ time for unweighted and undirected graph, where $MM(n)$ is the time to multiply two $n\times n$ matrices. Some history of the matrix multiplication problem:
\begin{itemize}
\item Naive: $O(n^3)$.
\item Strassen '69: $O(n^{2.8074})$.
\item Coppersmith \& Winograd '89: $O(n^{2.375477})$.
\item Strothers '10: $O(n^{2.374})$.
\item Vassilevska-Williams '11: $O(n^{2.372873})$.
\item Note that the lower bound for MM is still an open problem.($O(n^2)$??)
\end{itemize}

The notation $n^{\omega}$ is often used in papers since $\omega$ is being continuously improved.In this lecture, MM(n) is referred to as $n^{\omega}$.

First we observe the similarity between matrix multiplication and Floyd–Warshal. In fact, matrix multiplication is Floyd–Warshal where $(\min, +)$ is replaced by $(+, \times)$.



Let $A$ be the adjacency matrix, we have that $A^2_{ij}$ is the number of length 2 path from $i$ to $j$. More generally, $A^l_{ij}$ is the number of length $l$ path from $i$ to $j$. If we add the identity matrix to $A$, which is equivalent to adding all self-loop in the graph, we have that $A^l_{ij}$  number of paths of length $\leq l$.

A naive way of using matrix multiplication to compute shortest paths is to compute: $A, A^2, ..., A^n$ then let $D_{ij} = \min \limits_l s.t. A^l_{ij} > 0$. Two problems are $O(n^{\omega + 1})$ time and big number (which can be easily solve by just storing $A^l > 0$). Suppose we want a 2-approximation to $D_{ij}$, which is $X_{ij}$ such that $D_{ij} \in [\frac{X_{ij}}{2}, X_{ij}]$. We can compute $A, A^2, A^4 ... $ in $O(MM(n) \log n)$ by repeated squaring.

Now let $D'$ be the distance on $A^2$, that is the graph with all length 2 paths added as new edges. $D'$ can be computed recursively. Our goal is to find $D$ from $D'$ and $A$ in $O(MM(n))$ time. There are two cases:
\begin{itemize}
\item If $D_{ij}$ is even then $D'_{ij} = D_{ij} / 2$.
\item If $D_{ij}$ is odd  then $D'_{ij} = (D_{ij} + 1) / 2$.
\end{itemize}

So all we need to do is to find $D \mod 2$ (from $D'$ and $A$). Consider again two cases:
\begin{itemize}
\item If $D_{ij}$ is even then $ \forall u \in N(i), D'_{uj} \in \{D'_{ij}, D'_{ij} + 1\}$.
\item If $D_{ij}$ is odd  then $ \forall u \in N(i), D'_{uj} \in \{D'_{ij}, D'_{ij} - 1\}$ and $ \exists u \in N(i) \text{ s.t. } D'_{uj} = D'_{ij} - 1$.
\end{itemize}
That is because if the distance from $i$ to $j$ in $A$ is even ($2l$) then for a neighbor $u$ of $i$ the distance from $u$ to $j$ can only be $2l-1, 2l$ or $2l+1$. In $A^2$, the distance from $i$ to $j$ is $l$ and from $u$ to $j$ is $l$ or $l+1$ (if $D_{uj} = 2l-1$ in $A$ then it still takes $l$ steps from $u$ to $j$ in $A^2$). By a similar argument, we have the case for $D_{ij}$ odd. By summing over the neighbors, we have:

\begin{itemize}
\item If $D_{ij}$ is even then $ \sum_{u \in N(i)} D'_{uj}  \geq D'_{ij}|N(i)|   $.
\item If $D_{ij}$ is odd  then $ \sum_{u \in N(i)} D'_{uj}  <  D'_{ij}|N(i)| $.
\end{itemize}

Also, these sums can be expressed as matrix multiplication:

\begin{align}
\sum_{u \in N(i)} D'_{uj} &= \sum_{u \in [n]} A_{iu} D'_{uj}\\
&= (AD')_{ij}
\end{align}

So we compare $AD'$ to $D'|N(i)|$ to get $D_{ij} \mod 2$ and set $D = 2D' - (D \mod 2)$. Each round takes $n^{\omega}$ time and total time is $O(n^{\omega} \log n)$.


\section{Identifying shortest paths}
Now, given $D$ and $A$, we want to give an efficient algorithm for finding the shortest paths. For this lecture, we look at the case of a tripartite graph(Figure~\ref{fig:my_label}), with edges going from left to right. Let $A$,$B$ be the adjacency matrix for $\{V_1,V_2\}$ and $\{V_2,V_3\}$ respectively, then we're interested in finding $P_{ij} = k$ such that $A_{ik} \cap B_{kj} = 1$ in $O(n^\omega)$ time.
\begin{figure}[htbp]
\centering
\includegraphics[scale=0.5]{TripartiteGraph.jpg}
\caption{Tripartite Graph, $|V_i|=n \ \forall i$}
\label{fig:my_label}
\end{figure}

\paragraph{Easy Case.} Suppose there exists exactly one $k^*$ such that $A_{ik^*} \cap B_{k^*j} = 1$, then:
\begin{itemize}
\item Define $A'$ such that $A'_{ij} = A_{ij}.j$
\item Then $(A'B)_{ij} = \sum \limits_k k A_{ik} B_{kj} = k^*$. 
\item So, we can identify the witness $k^*$ for a path in $O(n^\omega)$ time.
\end{itemize}

\paragraph{Medium Case.} Suppose there exist $r$ witnesses $\{k_1,\ldots,k_r\}$ such that $A_{ik_d} \cap B_{k_dj} = 1$ for all $d \in [r]$, then:
\begin{itemize}
\item Define $A'$ such that $A'_{ij} = A_{ij}.j . \delta_j$, where $\delta_j$ is a Bernoulli r.v. such that $P[\delta_j = 1] = 1/r$.
\item Now, if exactly one of the $r$ $\delta_{k_t}=1$, then $(A'B)_{ij} = k_t$, so, we would have identified a witness.
\item Now, $P[\sum_{t} \delta_{k_t} = 1] = r . \frac{1}{r} . (1 - \frac{1}{r})^{r-1} \approx 1/e > 1/4$.
\item So, repeat $O(\log n)$ times and each time check result $A_{ik_t} \cap B_{k_tj} = 1$. Hence, the total runtime is $O(n^\omega \log(n))$.
\end{itemize}

\paragraph{Hard Case.} If we don't know the number of witnesses $r$, then:
\begin{itemize}
\item \textbf{Naive Strategy.} Run medium-case strategy for all $r=1,\ldots,n$. However, then runtime is $O(n^\omega . \log(n). n$.
\item Run medium-case strategy for all $r=1,2,4,\ldots,n$. For this stragy, runtime is $O(n^\omega . \log(n). \log(n)$.
\item To analyse it's correctness: Suppose $r:$true number of witnesses, and let $r'$ be our guess such that $r'/2 \leq r \leq r'$:
\begin{align*}
P[\text{exactly one of true witness $\delta_{k_t} = 1$}] &= r. \frac{1}{r'} . (1 - \frac{1}{r'})^{r-1} \\
&\geq 1/2e
\end{align*}
\item Since, we have a constant probability of success, running for $O(\log(n)$ iterations at $r'$ such that $r'/2 \leq r \leq r'$, suffices.
\item Hence, an overall runtime of $O(n^\omega . \log(n). \log(n)$ is sufficient for find a witness.
\end{itemize}

\nocite{*}
\bibliographystyle{abbrv}
\bibliography{references}



\end{document}
