Prob2b

Revisit Shortest Path
Algorithms
•
•
•
•
Dynamic Programming
Dijkstra’s Algorithm
Faster All-Pairs Shortest Path
Floyd-Warshall Algorithm
Dynamic Programming
Dynamic Programming
Define d * (u )  the length of the shortest path from s to u.
Initially, S  {s}, T  V  S .

In each iteration, find u  T : N (u )  S .
compute d * (u )  min
{d * (v)  c(v, u )}

vN ( u )
S  S  {u}
T  T  {u};
Stop if T  .
Lemma
Consider an acyclic network G  (V , E ) with a source node s
and a sink node t. Suppose ( S , T ) is a partition of V with s  S .
Then there exists u  T such that N  (u )  S .
Proof
Note that for any u  T , N  (u )  . If N  (u )  S , then
there exist v  N  (u ) such that v  T . If N  (v)  S , then
there exist w  N  (v) such that w  T . This process cannot
go forever. Finally, we' ll find z  T such that N  (z)  S.
Theorem
Dynamic programmin g works on any acyclic network
(even with negative weight).
2
-1
-1
2
1
Counterexample
Dynamic programmin g may not work in a network wi th
a cycle.
Dijkstra’s Algorithm
Dijkstra’s Algorithm
Define d (u )  min
{d * (v)  c(v, u )} for u  T .

vN ( u )  S
Initially, S  {s}, T  V  S .
In each iteration, find u  T : d (u )  min d ( w).
wT
S  S  {u}
T  T  {u}
update d ( w) for w  T ;
Stop if T  .
Lemma
Consider a network G  (V , E ) with a source node s
and a sink node t. Suppose ( S , T ) is a partition of V with s  S .
If arc - weights are nonnegativ e, then
d (u )  min d ( w)  d * (u )  d (u ).
wT
Proof of Lemma
T
w
u
s
S
Proof of Lemma
For contradict ion, suppose d (u )  min d (v)  d * (u ).
vT
Then there exists a path p from s to u such that
length( p)  d * (u )  d (u ).
Let w be the first node in T on path p. Then
d ( w)  length( p( s, w))
where p( s, w) is the piece of path p from s to w.
Since all arc - weights are nonnegativ e,
length( p)  length( p( s, w))  d ( w)  d (u )  d * (u )  length( p)
()
Theorem
Dijkstra' s Algorithm works on any network wi th
nonnegativ e arc - weights.
Counterexample
Dijkstra' s algorithm may not work in a network wi th
negative arc - weight.
3
-1
-2
2
1
Faster All-Pairs Shortest Path
Lemma
For any two nodes u and v, there exists a simple
shortest path between th em.
The network has no negative - weight cycle.
Theorem
Faster All - Pairs Shortest Path algorithm works
in any network wi thout negative - weight cycle.
Theorem
A network G contains a negative - weight cycle if and
only if L(G ) ( n 1)  L(G ) ( m ) for some m  n  1.
Floyd-Warshall Algorithm
Theorem
Floyd - Warshall algorithm works in any network
without negative - weight cycle.