















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!
















Shortest path in Directed Acyclic Graphs– Assumptions– Algorithm– Analysis– Proof of correctness
Statement: Let
G = (V, E) be
directed, with source
s,
a weighted, with weight function
w : E
and
contains no negative-weight cycle reachable from
s.
Then, after the
iterations of the
for
loop of
lines 2-4 of BELLMAN-FORD, we have
d[v] =
δ
(s, v)
for all vertices
v
that are reachable from
s.
Path relaxation property•^
If p
v
v
v
k^
, be a shortest path from s = v
0
to v
k^
and edges of p are relaxed in the order (
v
v
( v
v
v
k-
v
), then d( k
v
) = k
δ
( s
v
) k
Proof•^
We prove it using path-relaxation property.
-^
Consider any vertex
v
that is reachable from
s
And let
p
v
v
v
k^
, be any acyclic shortest
path from
s
to
v,
where
v
0
s
and
v
k^
v
As there are k+1 vertices in the path p, hence theremust be k edges in p.
-^
Because Graph has |V| vertices and path pcontains no cycle, hence path
p
has at most |
edges, and therefore,
k
Each of the |V| - 1 iterations of the for loop of lines2-4 relaxes all E edges.
Let BELLMAN-FORD be run on weighted, directedgraph G = (V, E), with source vertex s, and weightfunction w : E
If G contains no negative-weight cycles that arereachable from s, then– d[v] =
δ
(s, v) for all vertices v
V, and
the algorithm
returns TRUE
π
is shortest-paths
tree rooted at s.
If G does contain a negative weight cycle reachablefrom s, then the algorithm returns FALSE.
Theorem : Correctness of Bellman-Ford algorithm
Case 1
Suppose graph G contains no negative-weightcycles that are reachable from the source s.
-^
We first prove the claim that at termination,
d
[ v
δ
( s
v
) for all vertices
v
v
is reachable from
s
Lemma above
proves it.
v
is not reachable from
s
, then claim follows
from no-path property.
The predecessor subgraph property, along with theclaim, implies that
π^
is a shortest-paths tree.
(Once d[v] =
δ
(s, v) for all v
V, the predecessor
sub-graph is a shortest paths tree rooted at s)
Proof
Assume for the purpose of contradiction that theBellman-Ford algorithm returns TRUE.
-^
Thus,
d
[ v
]^ i
d
[ v
i -
w
( v
i -
v
) for i
i
k
Summing the inequalities around cycle
c
gives us
Contd..
^
k i
k i
i
i
i
k i
i
i
i
k i
i
v
v w
v d
v v w v d v d
1
1
1
1
1
1
1
1
) , ( ] [ ( ))
, ( ] [ ( ] [
-^
Since
v
0
=
v
, each vertex in k
c
appears exactly once in each
of the summations and, and so
-^
Of course
d
[ vi
] is finite for
i^
= 1, 2,...,
k
. Thus,
Which contradicts inequality (A). And hence itproves the theorem
Contd..^
k i
i
k i
i^
v d
v d
1
1
1
]
[
] [^
k i
i
i^
By relaxing edges of Directed Acyclic Graph (dag) G = (V, E)
according to topological sort of vertices
single source shortest path can be computed in
time
Shortest paths are always well defined in a dag– Since even if there are negative-weight edges no
negative weight cycle exists.
It starts topologically sorting dag, to impose linearordering of vertices.• If there is path from u to v then u precedes v.
-^
) to compute
f
v ] of each vertex
v
v
is colored black, assign it
f
v ).
v
onto the front of the linked list,
v}
5. return
the linked list.
started from the head of the list.
Example
Total Running Time =
y
t
s
5
2
7
- -
6
1
3
4
2
r
x
z
For each vertex
v
d
[ v
π
[ v
Considering
s
as root node
d
[ s
The vertices are taken intopologically sorted order
y
t
s
5
2
7
- -
6
1
3
4
2
r
x
z^ Considering vertex
r
Adj
[ r
s, t
d
[ s
d
[ r
w
( r, s
But (0 <
d
[ t
d
[ r
w
( r, t
But (
y
t
s 5
7
- -
6
1
3
4
2
r
x
z
Considering vertex
t
Adj
[ t ] =
x, y, z d [
x ] >
d
[ t
] +
w
( t, x
)
But (6 < 9) d [
y ] >
d
[ t
] +
w
( t, y
)
(∞
2 + 4)^ d
[ y
]^ ←
d
[ t
] +
w
( t, y
)
2 + 4 = 6
π[
y ]
←
t
d [
z ] >
d
[ t ] +
w
( t, z
)
(∞
2 + 2)^ d
[ z
]^ ←
d
[ t ] +
w
( t, z
)
2 + 2 = 4
π[
z ]
←
t
-
y
t
s 5
7
-
6
1
3
4
2
r
x
Considering vertex z
x
Adj
[ x
] =
y, z
d [
y ] >
d
[ x
] +
w
( x, y
)
(6 > 6 + (-1))
d [
y ]
←
d
[ x
] +
w
( x, y
)
6 + (-1) = 5
π[
y ]
←
x
d [
z ] >
d
[ x
] +
w
( x, z
)
But (4 < 6 + 1)