


























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



























Road map problem•^
This problem can be modeled as a graph problem
-^
Road map is a weighted graph:
set of
vertices
= set of cities
set of
edges
= road segments between cities
edge weight
= length between two cities
In a
shortest path problem
, a weighted, directed graph
is given with weight function
w : E
mapping
edges to real-valued weights.
-^
The
weight
of path
p =
is the sum of the
weights of its constituents edges
1 0
1 2 1 1 0 1
i
1 i
k
k
k i
-^
Single-source shortest path^ – G = (V, E)
find a shortest path from a given source
vertex s to each vertex v
V
-^
Single-destination shortest path^ – Find a shortest path to a given destination vertex
t
from
each vertex v
single-source
-^
Single-pair shortest path^ – Find a shortest path from u to v for given vertices u and v– Solve the single-source problem
-^
All-pairs shortest-paths^ – Find shortest path for every pair of vertices u and v of G
Statement
Given a weighted, directed graph
with
weight function
w : E
, let p =
v
, v 1
,..., v 2
k^
be
a shortest path from vertex
v
1
to vertex
v
, for any k
i, j
such that
i^
j
k
, let
p
ij^
v
, vi
i+
,..., v
j^
be
subpath of
p
from
v
to vertex i^
v
.^ j
Then,
p
ij^
is a
shortest path from
v
to i^
v
.j
Proof•^
We prove this lemma by contradiction
-^
If we decompose path
p
into
v
1
v
v
v
, k
then we have that
w
( p
w
( p
1 i
w
( p
) + ij
w
( p
) jk
p^ ij
p^ 1i
p^ jk
s
a: only one path
(s, a) = w(s, a) = 3
-^
s
b: only one path
(s, b) =
w(s, a) + w(a, b) = -
s
c: infinitely many paths
s, c
s, c, d, c
s, c, d, c, d, c
cycle has positive weight (6 - 3 = 3) s, c
shortest path with weight
(s, c) = w(s, c) = 5,
Positive cycle increases length of paths
s
-
3
a c
-b d
e^
f
g
4
5
6
8
-
2
(^3) -
7
s
-
3
a c
-b d
e^
f
g
4
5
6
8
-
2
(^3) -
7
-^
s^
e: infinitely many paths:
s, e
,
s, e, f, e
,
s, e, f, e, f, e
^
etc.
e, f, e
^
has negative weight: 3 + (- 6) = -
(s, e) =-
no shortest path exists between s and e
(s, f) = -
,^
(s, g) = -
There may be edges with negative weight.
-^
A cycle
p
v
,v 0
,…,v 1
,vk
0
is a
negative cycle
such
that
w(p)
If a graph
contains no negative weight
cycle reachable from the source
s
, then for all
v
, shortest path
δ
(s, v)
remains well defined.
If there is a negative weight cycles reachable froms, then shortest path weight are not well defined.
-^
If there is a path from u to v that contains a negativecycle, then shortest path is defined as
(u, v) = -
Can shortest paths contain cycles?
-^
Negative-weight cycles:
-^
Positive-weight cycles:– By removing the cycle we can get a shorter path
-^
Zero-weight cycles– No reason to use them– Can remove them to obtain a path with similar weight Note•^
We will assume that when we are findingshortest paths, the paths will have no cycles
No! No!
Let
be a weighted, directed graph with weight
function
w : E
and assume that
contains no
negative weight cycles reachable from the source vertex
s
, so that shortest paths are well defined.
A shortest path tree rooted at
s
is a directed subgraph
, where
and
Shortest path are not necessarily unique and neither areshortest path trees.
Shortest path are neither necessarily– unique and– nor shortest path trees
3
6
3
t^
x
s
(^35)
1
2
3
2
7
6 6 4
y^
z
0
9
5
11
3
t^
x
s
5
1
2
3
2
7
6 4
y^
z
0
9
5
11
3
t^
x
s
5
1
2
3
2
7
(^646)
y^
z
0
9
5
11
3
Relaxation
Relaxing
edge (u, v), testing whether we can
improve shortest path to v found so far through u–
If d[v] > d[u] + w(u, v)
we can improve the shortest path to v
update d[v] and
[v]
5
9
2
u^
v
5
7
2
u^
v RELAX(u, v, w)
5
6
2
u^
v
5
6
2
u^
v RELAX(u, v, w) d[v]
d[u] + w(u, v)
s^
s
d[v]
≥
d[u] + w(u, v)
Contd..
Running time =
s )
for
each vertex
v
do
d
[ v
π
[ v
d
[ s
u
v ,
w
if
d
[ v
d
[ u
w
( u
v )
then
d
[ v
d
[ u
w
( u
v )
π
[ v
u
Note:All the single-source shortest-paths algorithms, start by calling
INIT-SINGLE-SOURCE then relax edges. The algorithmsdiffer in the order and how many times they relax each edge