This preview shows pages 1–3. Sign up to view the full content.
CS 473
Homework 3 Solutions
Spring 2010
1. Below are four alternative greedy algorithms. For each algorithm, either prove that the algorithm constructs
an optimal schedule, or give a concrete counterexample showing that the algorithm is suboptimal.
(a) Choose the course that
ends latest
, discard all conﬂicting classes, and recurse.
Solution:
This algorithm does not compute an optimal schedule. Here is a counterexample:
The algorithm selects only the long interval, but the unique optimal schedule contains the
two short intervals.
±
Rubric:
2½ points max = 1½ for counterexample + 1 for proof of suboptimality. This
is not the only counterexample.
(b) Choose the course that
starts ﬁrst
, discard all conﬂicting classes, and recurse.
Solution:
This algorithm does not compute an optimal schedule. The same counterexample
from part (a) works.
±
Rubric:
2½ points max = 1½ for counterexample + 1 for proof of suboptimality. This
is not the only counterexample.
(c) Choose the course with
shortest duration
, discard all conﬂicting classes, and recurse.
Solution:
This algorithm does not compute an optimal schedule. Here is a counterexample:
The algorithm chooses only the middle interval, but the unique optimal schedule contains
the other two intervals.
±
Rubric:
2½ points max = 1½ for counterexample + 1 for proof of suboptimality. This
is not the only counterexample.
(d) Choose a course that
conﬂicts with the fewest other courses
(breaking ties arbitrarily), discard all
conﬂicting classes, and recurse.
Solution:
This algorithm does not compute an optimal schedule. Here is a counterexample:
A
B
C
D
E
F
G
H
I
J
K
The algorithm chooses course
B
ﬁrst, discards courses
E
and
F
, and then chooses one course
each from the sets
{
A
,
D
,
H
,
J
}
and
{
C
,
G
,
I
,
K
}
, for a total of three courses. But the optimal
schedule
{
D
,
E
,
F
,
G
}
contains four courses.
±
Rubric:
2½ points max = 1½ for counterexample + 1 for proof of suboptimality. This
is not the only counterexample.
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentCS 473
Homework 3 Solutions
Spring 2010
2. Given a quantity of money
x
, and a set of coin denominations
b
1
,...,
b
k
, your algorithm should compute
how to make change for
x
with the fewest number of coins.
(a) Show that the following greedy algorithm does
not
work for all currency systems: If
x
=
0
, do nothing.
Otherwise, ﬁnd the largest denomination
c
≤
x
, issue one
c
cent coin, and recursively give
x

c
cents in change.
Solution:
Consider the predecimal British currency system, which had coins worth ½ cent
(halfpenny), 1 cent (penny), 3 cents (threepence), 6 cents (sixpence), 12 cents (shilling),
24 cents (ﬂorin), and 30 cents (half crown). Before decimalisation, the most efﬁcient way
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '08
 Chekuri,C
 Algorithms

Click to edit the document details