Cs445 — Homework #5
All pairs shortest path, Network Flow, and
Matching
Due: 4/5/2005 during class meeting.
1. Let
G
(
V, E
) be a graph, with weights assigned to the edges (positive and nega
tive). Explain how to modify Johnson’s algorithm so the output of the algorithm
is an
n
×
n
matrix that speciFes for every pairs of vertices
u, v
∈
V
, the Frst
edge in the shortest path from
u
to
v
.
The running time of the algorithm is
O
(

E

V

log

E

)
Answer:
The initialization of the matrix FirstEdgeWeight[], will be done as
follows: For all
v
∈
adj
[
s
]
, FirstEdgeWeight[s,v] = w(s,v).
The remaining entries in the matirx will be initialized to
∞
.
Instead of calling Relax(u,v,w), Dijkstra’s algorithm will make a call to Re
lax(s,u,v,w), where the starting vertex s is also speci±ed.
The code of Relax(s,u,v,w) is as given below.
The edge (u,v) is added to the
shortest path from s to v, when the values of pi and d are updated inside
the relax procedure.
Thus, the correctness of the procedure follows from the
correctness of Dijkstra’s algorithm.
Relax(s,u,v,w)
{
if( d[v] > d[u] + w(u,v) )
{
d[v] = d[u] + w(u,v);
pi[v] = u;
FirstEdgeWeight[s,v] = FirstEdgeWeight[s,u];
}
}
2. Assume
G
(
V, E
) is a graph where the weights of all edges are positive. You ran
Johnson algorithm on this graph. What is the values
h
(
v
) and ˆ
w
(
u, v
) given by
the algorithm ? Prove.
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentAnswer:
The values of
h
(
v
)
will be 0 for all
v
∈
V
. Consequently,
ˆ
w
(
u, v
) =
w
(
u, v
)
.
In Johnson’s algorithm, the values of
h
(
v
)
, are obtained by running the Bellman
Ford algorithm, using the newly added vertex s, as the starting vertex.
More
over, edges with weight 0 are added from s to each
v
∈
V
.
Thus, the shortest
path from s to each
v
cannot be greater than zero.
Now, since all weights are
given to be positive, it is not possible to ±nd a path from s to any
v
, with
weight less than zero. Thus, it is proved that
h
(
v
)
will be 0 for all
v
∈
V
, and
consequently,
ˆ
w
(
u, v
) =
w
(
u, v
)
.
3. Let
G
(
V, E
) be a graph with positive and negative weights given its edges.
Assume that for each vertex
v
∈
V
you are also given a value
h
(
v
) with the
property that for every edge (
u, v
)
∈
E
,
w
(
u, v
) +
h
(
v
)

h
(
u
)
≥
0. (Note  the
values
h
(
v
) are given to you — you do not need to compute them). Assume that
in addition, you are given
sets
of vertices
X
1
, X
2
. . . X
k
, such that
X
i
∩
X
j
=
∅
(that is, each vertex
v
∈
V
belongs to at most one set
V
i
). DeFne
δ
(
X
i
, X
j
) = min
{
δ
(
u, v
)

u
∈
X
i
, v
∈
X
j
}
Suggest an algorithm that computes
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '06
 Williams
 Graph Theory, residual graph, ford Fulkerson algorithm

Click to edit the document details