CS 473: Algorithms, Fall 2010
HW 7 (due Tuesday, October 26th)
This homework contains four problems.
Read the instructions for submitting homework on
the course webpage
. In particular,
make sure
that you write the solutions for the problems on
separate sheets of paper; the sheets for each problem should be stapled together. Write your name
and netid on each sheet.
Collaboration Policy:
For this home work, Problems 13 can be worked in groups of up to 3
students each.
Problem 0 should be answered in Compass as part of the assessment HW7Online and
should be done individually.
1. (25 pts) Let
G
= (
V,E
) be an undirected graph with edge costs
c
e
. Given an integer
k
where
1
≤
k
≤
n

1, describe an algorithm that ﬁnds the minimumcost forest in
G
that contains
k
edges.
Solution
:
In order to ﬁnd a minimumcost forest in G, we simply run Kruskal’s algorithm until k edges
are inserted. The running time will be
O
(
m
log
m
) since this is the running time for Kruskal’s,
and we also need this much time in order to sort the edges. Note, if you interpreted the
question to mean “the minimumcost forest with at least k edges”, then you should continue
running Kruskal’s algorithm past the point of k edges as long as the edge weights are negative.
Now we must prove this algorithm is correct. Clearly it returns a forest, since at any point in
Kruskal’s algorithm we have a forest. Let
F
be the forest that our algorithm returns. Suppose
that there was a Forest,
F
0
, with
k
edges that was cheaper, and let
e
j
be the minimum weight
edge such that
e
j
is in
F
but not in
F
0
. Speciﬁcally, let
F
0
be the optimal forest that maximizes
the value of
j
in the list of edges sorted by increasing weight,
e
1
,...,e
m
.
Consider adding
e
j
to
F
0
. If
e
j
does not create a cycle in
F
0
, then we can simply add
e
j
and remove the heaviest weight edge in
F
0
to obtain a cheaper forest with
k
edges, which
contradicts the optimality of
F
0
. So assume that adding
e
j
creates a cycle,
C
. We know that
for all
i
such that
i < j
,
e
i
is in both
F
and
F
0
. Since
F
did not contain a cycle with
e
j
,
there must be some edge