Graphs II - Shortest paths
Single Source Shortest Paths All Sources Shortest Paths
some drawings and notes from prof. Tom Cormen
Graphs II - Shortest paths Single Source Shortest Paths All Sources - - PowerPoint PPT Presentation
Graphs II - Shortest paths Single Source Shortest Paths All Sources Shortest Paths some drawings and notes from prof. Tom Cormen Single Source SP Context: directed graph G=(V ,E,w), weighted edges The shortest path (SP) between
Single Source Shortest Paths All Sources Shortest Paths
some drawings and notes from prof. Tom Cormen
s edges weights
the cycle few more times, minimum weight is -∞.
weight from the source
, we “relax edge (u,v)” by replacing the estimate ESP(s,v) =7 .
edges
edges step |V|-1 times, to get all SP-s
5 7 5 5 6 6 6 6 6 7 7 7 8 8 8 1 2 3 1 8 1 2 3 2 3 3 2 4 4 1 2
5 7 5 5 6 6 6 6 6 7 7 7 8 8 8 1 2 3 1 8 1 2 3 2 3 3 2 4 4 1 2
∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞
5 7 5 5 6 6 6 6 6 7 7 7 8 8 8
2 1 1 3
1 2 3 1 8 1 2 3 2
7
3 3 2 4 4 1 2
∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞
5 7 5 5 6 6 6 6 6 7 7 7 8 8 8
2 1 1 3
1 2 3 1 8
6 4 4 5 5 3 7
1 2 3 2
7 8 9
3 3 2 4 4 1 2
∞
5 7 5 5 6 6 6 6 6 7 7 7 8 8 8
2 1 1 3
1 2 3 1 8
6 4 4 5 5 3 7 6 7 6 6
1 2 3 2 3 3 2 4 4 1 2
amount of time, but it has to be in the right order
these edges, in this precise order: a1 in the first round, a2 in the second round, etc.
enforce correctness in all possible cases
these edges, in this precise order: a1 in the first round, a2 in the second round, etc.
these edges, in this precise order: a1 in the first round, a2 in the second round, etc.
these edges, in this precise order: a1 in the first round, a2 in the second round, etc.
these edges, in this precise order: a1 in the first round, a2 in the second round, etc.
these edges, in this precise order: a1 in the first round, a2 in the second round, etc.
these edges, in this precise order: a1 in the first round, a2 in the second round, etc.
these edges, in this precise order: a1 in the first round, a2 in the second round, etc.
these edges, in this precise order: a1 in the first round, a2 in the second round, etc.
these edges, in this precise order: a1 in the first round, a2 in the second round, etc.
these edges, in this precise order: a1 in the first round, a2 in the second round, etc.
We ¡want ¡to ¡find ¡the ¡shortest ¡path ¡from ¡s ¡to ¡every ¡node
A4er ¡ini6aliza6on, ¡we ¡have ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡for ¡all ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡and ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡for ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡
We ¡are ¡at ¡node ¡s
Test ¡whether ¡we ¡can ¡improve ¡the ¡shortest ¡path ¡to ¡t ¡found ¡so ¡far ¡by ¡going ¡through ¡s
Update ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡and ¡
Test ¡whether ¡we ¡can ¡improve ¡the ¡shortest ¡path ¡to ¡y ¡found ¡so ¡far ¡by ¡going ¡through ¡s
Update ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡and ¡
All ¡edges ¡leaving ¡s ¡have ¡been ¡tested
We ¡are ¡at ¡node ¡y
Test ¡whether ¡we ¡can ¡improve ¡the ¡shortest ¡path ¡to ¡t ¡found ¡so ¡far ¡by ¡going ¡through ¡y
Update ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡and ¡
Test ¡whether ¡we ¡can ¡improve ¡the ¡shortest ¡path ¡to ¡x ¡found ¡so ¡far ¡by ¡going ¡through ¡y
Update ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡and ¡
Test ¡whether ¡we ¡can ¡improve ¡the ¡shortest ¡path ¡to ¡z ¡found ¡so ¡far ¡by ¡going ¡through ¡y
Update ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡and ¡
All ¡edges ¡leaving ¡y ¡have ¡been ¡tested
We ¡are ¡at ¡node ¡z
Test ¡whether ¡we ¡can ¡improve ¡the ¡shortest ¡path ¡to ¡s ¡found ¡so ¡far ¡by ¡going ¡through ¡z
Test ¡whether ¡we ¡can ¡improve ¡the ¡shortest ¡path ¡to ¡x ¡found ¡so ¡far ¡by ¡going ¡through ¡z
Update ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡and ¡
All ¡edges ¡leaving ¡z ¡have ¡been ¡tested
We ¡are ¡at ¡node ¡t
Test ¡whether ¡we ¡can ¡improve ¡the ¡shortest ¡path ¡to ¡y ¡found ¡so ¡far ¡by ¡going ¡through ¡t
Test ¡whether ¡we ¡can ¡improve ¡the ¡shortest ¡path ¡to ¡x ¡found ¡so ¡far ¡by ¡going ¡through ¡t
Update ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡and ¡
All ¡edges ¡leaving ¡t ¡have ¡been ¡tested
We ¡are ¡at ¡node ¡x
Test ¡whether ¡we ¡can ¡improve ¡the ¡shortest ¡path ¡to ¡z ¡found ¡so ¡far ¡by ¡going ¡through ¡x
All ¡edges ¡leaving ¡x ¡have ¡been ¡tested. Every ¡vertex’s ¡shortest ¡path ¡from ¡s ¡has ¡been ¡determined. ¡We ¡are ¡done.
, there is a relaxation sequence of its edges in path-order
O(logV) and decrease-key is O(1) ; total O(E+VlogV)
all edges from u
Lesson 2: All Sources Shortest Paths
subpaths P(i->k) and P(k->j) must be also optimal
vertices {1,2,...m}
“last” intermediary
; the “*” means “a=min{a, Cik(m-1) + wkj}“ inner
Ford-SSSP