Docsity

Greedy Algorithms and Dynamic Programming for Making Change, Assignments of Algorithms and Programming

Toggle sidebar
bg1
Head-Banging Session 6
Fall 2008 CS 473: Algorithms
Due to Midterm 1, this HBS will be dedicated to review, with one new problem on greedy algorithms and
dynamic programming.
Problem 1.[The Problem with Change]
Consider the problem of making change for ncents using the least number of coins.
1. Describe a greedy algorithm to make change consisting of quarters, dimes, nickels, and pennies. Prove
that your algorithm yields an optimal solution.
2. Suppose that the available coins have the values c0, c1, ..., ckfor some integers c > 1 and k≥1. Show
that the greedy algorithm always yields an optimal solution.
3. Give a set of 4 coin values for which the greedy algorithm does not yield an optimal solution, show
why.
4. Give a dynamic programming algorithm that yields an optimal solution for an arbitrary set of coin
values.
1

Partial preview of the text

Download Greedy Algorithms and Dynamic Programming for Making Change and more Assignments Algorithms and Programming in PDF only on Docsity!

Head-Banging Session 6

Fall 2008 CS 473: Algorithms

Due to Midterm 1, this HBS will be dedicated to review, with one new problem on greedy algorithms and dynamic programming.

Problem 1. [The Problem with Change] Consider the problem of making change for n cents using the least number of coins.

  1. Describe a greedy algorithm to make change consisting of quarters, dimes, nickels, and pennies. Prove that your algorithm yields an optimal solution.
  2. Suppose that the available coins have the values c^0 , c^1 , ..., ck^ for some integers c > 1 and k ≥ 1. Show that the greedy algorithm always yields an optimal solution.
  3. Give a set of 4 coin values for which the greedy algorithm does not yield an optimal solution, show why.
  4. Give a dynamic programming algorithm that yields an optimal solution for an arbitrary set of coin values.