Lecture 6 - Shortest Path Algorithms

Matrix Multiplication Algorithm

Let $\delta^{(m)}_{i,j}$ be the length of a shortest path from $i$ to $j$, subject to the condition that the path contains no more than $m$ arcs. It follows that:

image-20210218170830816

This is the recurrence equation. We are slicing the problem of shortest path into layers, with each layer containing $m$ edges. If $m = n$ then we have the shortest path, where $n$ is the number of vertices.

We define a new matrix multiplication $p_{i,j} = A \bigotimes B$ as $p_{i,j} = min_k{a_{i,k} + b_{i,k}}$.

Let $W = w(i,j)$ be the matrix of arc weights. Let further $D^{(m)} = \delta^{(m)}_{i,j}$ be the matrix of the $m$th order approximation:

image-20210218171501068

Note that $D^{(0)}$ is the identity matrix. It follows that $D^{(n-1)} = W^{(n-1)}$. Hence we can reduce the number of computational steps to solve by calculating $W^2 = W \bigotimes W, W^4 = W^2 \bigotimes W^2$

Okay I’m lost. Next slide pls

Example for the Matrix Multiplication Algorithm

We are given the directed graph with negative edges (note that we don’t have negative cycles as that would make computation last infinitely):

image-20210218172032388

This produces the following matrix

image-20210218172119958

Multiplication happens like this:

image-20210218172232101

$D = W^4 \bigotimes W =$image-20210218172239187

Instead of multiplication, we perform addition, and instead of addition, we take the minimum values

Floyd-Warshall Algorithm

Also performs the same task, finding the shortest path in a directed graph with possible negative edges but no negative cycles.

Definition

Let $\delta^m_{i,j}$ be the length of a shortest path from $i$ to $j$ in $G$ that uses only the vertices in ${1,…m,i,j}$

Then $\delta^{n}_{ij}$ provides the distances between any pair $(i,j)$ of vertices in $G$ and can be computed by the following recurrence relation:

image-20210218172908401

Operations on the matrix using this algorithm (Eq. 5, I don’t remember seeing this I’m sure it’s in the notes)

image-20210218173231591

This algorithm has a running time of $O(n^3)$, since we do the pass $n$ times, filling $n^2$ values into the matrix.

Pseudocode

image-20210218173451779

Example on the same graph

image-20210218173530234

HAIKO GIVE ME MY GRAPH BACK

image-20210218173901614

omg he returned.

This is now a live commentary.

Correctness

Since we allow negative weights, we have to ensure that the concatenation of the paths $(i,…,m)$ and $(m,…,j)$ is a simple path. We apply induction on $m$