Introduction to Algorithms
November 20, 2006
Massachusetts Institute of Technology
6.046J/18.410J
Professors Erik Demaine and Madhu Sudan
Problem Set 8 Solutions
Problem Set 8 Solutions
Problem 81.
Shortest paths in graphs with alternative distance measures
Let
G
= (
V,E
)
be a graph with a real weight
w
(
u,v
)
assigned to each edge
(
u,v
)
∈
E
. Let
p
=
v
1
→
v
2
→ ··· →
v
k
be a path in
G
. In class we deﬁned the weight of
p
as
w
(
p
) =
k

1
X
i
=1
w
(
v
i
,v
i
+1
)
.
Although this deﬁnition of path weight is natural, in some applications alternative deﬁnitions may
be more appropriate. In this problem you will see several alternative deﬁnitions of path weight.
Your goal is to design efﬁcient algorithms for the singlesource shortestpaths problem under each
of these deﬁnitions. That is, in each of the three cases below, give an efﬁcient algorithm to ﬁnd the
shortestpath weights from a given source node
s
to all other nodes in
G
. The running time of each
algorithm should be bounded by a polynomial in

V

and

E

.
(a)
Let
G
= (
V,E
)
be a directed graph and
w
:
E
→
R
be a weight function. Assume that
w
takes only positive values. Deﬁne the weight of a path
p
=
v
1
→
v
2
→ ··· →
v
k
in
G
to be the
product
of all edge weights along the path, i.e.,
w
(
p
) =
k

1
Y
i
=1
w
(
v
i
,v
i
+1
)
.
Solution:
Consider a new weight function
w
0
:
E
→
R
,
deﬁned by
w
0
(
u,v
) =
lg
w
(
u,v
)
.
Note that
w
0
is well deﬁned since
w
(
u,v
)
is always positive. Observe that
for every path
p
=
v
1
→
v
2
→ ··· →
v
k
in
G
we have
w
(
p
) =
k

1
Y
i
=1
w
(
v
i
,v
i
+1
) = 2
∑
k

1
i
=1
w
0
(
v
i
,v
i
+1
)
= 2
w
0
(
p
)
.
For
v
∈
V
let
d
(
v
)
denote the minimal weight of a path from the source to
v
with
respect to the weight function
w.
Similarly let
d
0
(
v
)
denote the minimal weight of a
path from the source to
v
with respect to the weight function
w
0
.
The identity above
implies that
d
(
v
) = 2
d
0
(
v
)
.
It remains to note that
d
0
(
v
)
can be computed for all
v
∈
V
by a single invocation of a standard BellmanFord algorithm with the weight function
w
0
on edges.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document2
Problem Set 8 Solutions
(b)
Consider a directed graph
G
= (
V,E
)
where weights are assigned to vertices rather
than edges. Let
w
:
V
→
R
be such a weight function. Deﬁne the weight of a path
p
=
v
1
→
v
2
→ ··· →
v
k
in
G
to be the sum of all node weights along the path, i.e.,
w
(
p
) =
k
X
i
=1
w
(
v
i
)
.
Solution:
Deﬁne a function
w
0
:
E
→
R
,
by the following rule:
w
0
(
u,v
) =
w
(
v
)
.
In other words, assign every edge the weight of its end node. It is easy to see that,
for every path
p
=
v
1
→
v
2
→ ··· →
v
k
in
G
,
w
(
p
) =
w
0
(
p
) +
w
(
v
1
)
. Therefore
a single invocation of a standard shortest paths algorithm that allows negative cycles
(say, BellmanFord) with weights
w
0
on edges solves the problem.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '08
 ErikDemaine
 Algorithms, Graph Theory, WI, Shortest path problem

Click to edit the document details