This preview shows page 1. Sign up to view the full content.
CMPT 405/705 — Design and Analysis of Algorithms
Exercises on Graphs and Greedy Algorithms.
Due: Thursday,
September 24th (at the beginning of the class)
Reminder: the work you submit must be your own.
Any collaboration and consulting outside
resourses must be explicitely mentioned on your submission.
1. Consider the problem of making change for
n
cents using the fewest number of coins. Assume
each coin’s value is an integer.
(a) Describe a greedy algorithm to make change consisting of quaters, dimes, nickels, and
pennies. Prove that your algorithm is optimal.
(b) Give a set of coins for which the greedy algorithm does not yield an optimal solution.
Your set should include a penny so that there is a solution for every value of
n
.
2. Give an algorithm to detect whether a given undirected graph contains a cycle. If the graph
contains a cycle, then your algorithm should output one (not all). The running time of your
algorithm should be
O
(
m
+
n
)foragraphw
ith
n
vertices and
m
edges.
This is the end of the preview. Sign up
to
access the rest of the document.
 Fall '09
 Bulatov
 Algorithms

Click to edit the document details