Shortest Paths
Shortest Paths
SSSP, non-neg
s 2 e
6 2
c
6 1
d
Dijkstra’s Algorithm
SSSP, non-neg
s b c d e
L(x) 0 ∞ ∞ ∞ ∞
2 b 2
s 2 e
6 2
c x <- extractmin
s b c d e
L(x) 0 2 6 6 ∞
2 b 2
s 2 e
6 2
c x <- extractmin
s b c d e
L(x) 0 2 4 6 4
2 b 2
s 2 e
6 2
c x <- extractmin
s b c d e
L(x) 0 2 4 6 4
2 b 2
s 2 e
6 2
c x <- extractmin
s b c d e
L(x) 0 2 4 5 4
2 b 2
s 2 e
6 2
c x <- extractmin
s b c d e
L(x) 0 2 4 5 4
2 b 2
s 2 e
6 2
c x <- extractmin
s b c d e
L(x) 0 ∞ ∞ ∞ ∞
2 e for t = 1 to n-1
s
6 -2 for all vertices x
c // "relax” all the edges out of x
6 1 L(y) <- min ( L(y), L(x) + w(x,y) )
s b c d e
L(x) 0 2 2 5 4
2 e for t = 1 to n-1
s
6 -2 for all vertices x
c // "relax” all the edges out of x
6 1 L(y) <- min ( L(y), L(x) + w(x,y) )
s b c d e
L(x) 0 2 2 5 4
2 e for t = 1 to n-1
s
6 -2 for all vertices x
c // "relax” all the edges out of x
6 1 L(y) <- min ( L(y), L(x) + w(x,y) )
Non-neg weights:
n Dijkstras O(mn + n2 log n)
Neg weights:
n B-F-M O(mn2)
Johnson’s Algorithm
APSP, neg wts OK
Non-neg weights:
n Dijkstras O(mn + n2 log n)
Neg weights:
n B-F-M O(mn2)
Neg weights:
B-F-M + n Dijkstras O(mn + n2 log n)
Neg weights:
Floyd-Warshall O(n3)
Non-neg weights:
n Dijkstras O(mn + n2 log n)
Neg weights:
n B-F-M O(mn2)
Neg weights:
B-F-M + n Dijkstras O(mn + n2 log n)
Neg weights:
Floyd-Warshall O(n3)
Neg weights:
Naïve Min-Sum-Product O(n3 log n)