All-Pairs Shortest Paths

Design and Analysis of Algorithms

Jesus A. Gonzalez

July 17, 2019

Problem of Finding All Pairs of Shortest Path

Problem of Finding All Pairs of Shortest Path

Modeling the Problem

\(\delta w_{i,j} = \begin{cases} 0 &\mbox{if } i = j\\ w_{i,j} &\mbox {if } i \not= j, (i,j) \in E\\ \infty &\mbox{if } i \not= j, (i,j) \notin E\\ \end{cases}\)

Modeling the Problem

Modeling the Problem

Shortest Paths and Matrix Multiplication

Dynamic Programming Reminder

Optimum Substructure of a Shortest Path - Proof to lemma 24.1

Recursive Solution for All Pairs of Shortest Paths

\(l_{ij}^{(0)} = \begin{cases} 0 &\mbox{if } i = j,\\ \infty &\mbox{if } i \not= j.\\ \end{cases}\)

Recursive Solution for All Pairs of Shortest Paths

Computing All Weights of the Shortest Path - Bottom-UP

Algorithm

Algorithm

Algorithm

Example

Faster Algorithm

Faster Algorithm

Floyd-Warshall Algorithm

Floyd-Warshall Algorithm

Floyd-Warshall Algorithm

  1. \(k\) is not an intermediate vertex of \(p\)
    • \(i \overset{p}{\longrightarrow} j\)
  2. \(k\) is an intermediate vertex of \(p\)
    • \(i \overset{p_1}{\longrightarrow} k \overset{p_2}{\longrightarrow} j\)
    • Contains vertices from \(\{1, 2, \dots, k-1\}\)
    • \(p_1\) is the shortest path from \(1\) to \(k\)
    • \(p_2\) is the shortest path from \(k\) to \(j\)
    • This is because of lemma 24.1

Recursive Solution

Floyd-Warshall Algorithm

Floyd-Warshall Algorithm

Example

Example

Example

Example

Construction of the Shortest Path

Exercise