Computer Science 130B
Winter 2012
Homework #3
Due: 4:00pm Feb 24th
Problem 1
We show in written assignment # 2 that the greedy algorithm can solve the coin change problem where the
denominations of coins are 1 (penny), 5 (nickel), 10 (dime), and 25 (quarter). Do you think that the greedy algorithm
will work for all possible coin denominations? If yes, prove that the greedy algorithm always uses the smallest number
of coins to make change for any coin denomination. If not, given a counterexample that the greedy algorithm may not
use the smallest number of coins to make change, and then design a dynamic programming algorithm that solves the
coin change problem using the smallest number of coins. What is the complexity of your algorithm?
Problem 2
Consider the allpairsshortestpaths problem again. Recall that we discussed a dynamic programming
solution which can be stated as:
A
k
(
i,j
)=
min
{
A
k

1
(
i,j
)
,A
k

1
(
i,k
)+
A
k

1
(
k,j
)
}
.
Or, the shortest path between vertices
i
and
j
without going through vertices of index higher than
k
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '12
 Drexel
 Computer Science, Dynamic Programming, Greedy algorithm, DI

Click to edit the document details