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