Coin Change Problem: Fewest Coins Algorithm and Divide-and-Conquer Approach, Study notes of Data Structures and Algorithms

The coin change problem, where given a set of coin types and an amount of change, the goal is to determine the fewest number of coins required. Two approaches are explored: a 'greedy' algorithm using us coin types {1, 5, 10, 25, 50} and a divide-and-conquer algorithm. The document also includes a recursive relationship and a few levels of the recursion tree for 29-cents change.

Typology: Study notes

2012/2013

Uploaded on 04/30/2013

jut
jut 🇮🇳

4.5

(63)

77 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1. Consider the coin-change problem: Given a set of coin types and an amount of change to be returned, determine the
fewest number of coins for this amount of change.
a) What "greedy" algorithm would you use to solve this problem with US coin types of {1, 5, 10, 25, 50} and a change
amount of 29-cents?
b) Do you get the correct solution if you use this algorithm for coin types of {1, 5, 10, 12, 25, 50} and a change
amount of 29-cents?
2. One way to solve this problem in general is to use a divide-and-conquer algorithm. Recall the idea of
Divide-and-Conquer algorithms.
Solve a problem by:
dividing it into smaller problem(s) of the same kind
solving the smaller problem(s) recursively
use the solution(s) to the smaller problem(s) to solve the original problem
a) For the coin-change problem, what determines the size of the problem?
b) How could we divide the coin-change problem for 29-cents into smaller problems?
c) If we knew the solution to these smaller problems, how would be able to solve the original problem?
Data Structures (CS 1520) Lecture 10 Name:_________________
L
ecture 10
- Page
1
Docsity.com
pf2

Partial preview of the text

Download Coin Change Problem: Fewest Coins Algorithm and Divide-and-Conquer Approach and more Study notes Data Structures and Algorithms in PDF only on Docsity!

  1. Consider the coin-change problem: Given a set of coin types and an amount of change to be returned, determine the fewest number of coins for this amount of change.

a) What "greedy" algorithm would you use to solve this problem with US coin types of {1, 5, 10, 25, 50} and a change amount of 29-cents?

b) Do you get the correct solution if you use this algorithm for coin types of {1, 5, 10, 12, 25, 50} and a change amount of 29-cents?

  1. One way to solve this problem in general is to use a divide-and-conquer algorithm. Recall the idea of Divide-and-Conquer algorithms. Solve a problem by:  dividing it into smaller problem(s) of the same kind  solving the smaller problem(s) recursively  use the solution(s) to the smaller problem(s) to solve the original problem

a) For the coin-change problem, what determines the size of the problem?

b) How could we divide the coin-change problem for 29-cents into smaller problems?

c) If we knew the solution to these smaller problems, how would be able to solve the original problem?

Data Structures (CS 1520) Lecture 10 Name:_________________

Lecture 10Docsity.com - Page 1

  1. After we give back the first coin, which smaller amounts of change do we have?

29 cents

1-cent coin 5-cent coin 10-cent coin

12-cent coin 25-cent coin^ 50-cent coin Possible First Coin

Original Problem

Smaller problems

  1. If we knew the fewest number of coins needed for each possible smaller problem, then how could determine the fewest number of coins needed for the original problem?
  2. Complete a recursive relationship for the fewest number of coins.

FewestCoins(change) =

1 if change^ CoinSet

min( FewestCoins( ) ) + if change CoinSet

coin ∈CoinSet and coin change

  1. Complete a couple levels of the recursion tree for 29-cents change using the set of coins {1, 5, 10, 12, 25, 50}.

29 cents

1-cent coin 5-cent coin 10-cent coin

12-cent coin 25-cent coin^ 50-cent coin Possible First Coin

Original Problem

Smaller problems

Data Structures (CS 1520) Lecture 10 Name:_________________

Lecture 10Docsity.com - Page 2