SLIDE 1
1
Single Single-
- Source Shortest Paths
Source Shortest Paths
Def.
- Def. Given a weighted directed graph
Given a weighted directed graph ( (G(V,E),w G(V,E),w) ), we , we define the define the weight weight of
- f a
a path path as the sum of the weights of it as the sum of the weights of it’ ’s constituent edges, s constituent edges, i.e., as i.e., as We define the We define the shortest shortest-
- path
path weight weight
- f
- f
from from u u to to v v as as A A shortest shortest path path is one of shortest path weight. is one of shortest path weight.
1
, , ,
k
p v v v = …
1 1
( ) ( , )
k i i i
w p w v v
− =
= ∑ { } { }
min ( ) : ( , )
p
w p u v if a path from u to v u v
- therwise
δ → ∃ → ∃ = ∞
( , ) u v δ
Single Single-
- Source Shortest Paths Problem:
Source Shortest Paths Problem: Given a Given a weighted graph weighted graph ((G=( ((G=(V,E),w V,E),w), ), find a shortest path find a shortest path from a given source vertex to each vertex from a given source vertex to each vertex
s V ∈ v V ∈
- Single
Single-
- destination shortest
destination shortest-
- paths problem:
paths problem: Find a Find a shortest path to a given destination shortest path to a given destination t t for each for each vertex vertex v v. .
- Single
Single-
- pair shortest
pair shortest-
- path problem:
path problem: For given For given vertices vertices u u and and v v, find a shortest path from , find a shortest path from u u to to v v
- All
All-
- pairs shortest
pairs shortest-
- paths problem:
paths problem: For all pairs of For all pairs of vertices vertices ( (u,v u,v) ), find a shortest path from , find a shortest path from u u to to v v. . Other variants 0f this problem Other variants 0f this problem
Optimal Substructure Optimal Substructure
Lemma 24.1(Page 582). Given a weighted directed Lemma 24.1(Page 582). Given a weighted directed graph graph (G=( (G=(V,E),w V,E),w) ). Let be a . Let be a shortest path from shortest path from v v1
1 to
to v vk
k, then for every
, then for every i,j i,j s.t s.t. . , the , the subpath subpath is is a shortest path from a shortest path from v vi
i to
to v vj
j.
. Proof: Proof:
1 2
, , ,
k
p v v v = … 1 i j k ≤ ≤ ≤ ≤ ≤
, ,
ij i j
p v v = …
1
1
ij jk i
p p p i j k
v v v v → → → → → Single Single-
- Source Shortest Paths
Source Shortest Paths
A shortest path exists A shortest path exists iff iff there are no there are no reachable negative cycles. Each node reachable negative cycles. Each node v v contains a field contains a field d[v d[v] ] which is an upper bound which is an upper bound
- f
- f δ
δ(s,v (s,v) )
Single Single-
- Source Shortest Paths
Source Shortest Paths
The shortest path is not unique. The shortest path is not unique.
Shortest Path Representation Shortest Path Representation
For each vertex For each vertex , we maintain a , we maintain a predecessor predecessor that is either a vertex or that is either a vertex or NIL
- NIL. The algorithms given in this chapter will
. The algorithms given in this chapter will set the predecessor so that points set the predecessor so that points to the previous vertex on the shortest path from to the previous vertex on the shortest path from source source s s to to v
- v. In this way, the shortest path is