Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coin Change : Greedy Approach

The Problem is making n cents change with quarters, dimes, nickels, and pennies, and using the least total number of coins. In the particular case where the four denominations are quarters,dimes, nickels, and pennies, we have c1 = 25, c2 = 10, c3 = 5, and c4 = 1.

If we have only quarters, dimes, and pennies (and no nickels) to use, the greedy algorithm would make change for 30 cents using six coins—a quarter and five pennies—whereas we could have used three coins, namely, three dimes.

Given a set of denominations, how can we say whether greedy approach creates an optimal solution?

like image 674
bhavya Avatar asked May 09 '15 10:05

bhavya


People also ask

Is coin change problem greedy?

The famous coin change problem is a classic example of using greedy algorithms.

When can a greedy algorithm solve the coin change problem?

Solution for coin change problem using greedy algorithm is very intuitive. Basic principle is : At every iteration in search of a coin, take the largest coin which can fit into remaining amount we need change for at the instance. At the end you will have optimal solution. 1.

What is greedy approach example?

Greedy is an algorithmic paradigm that builds up a solution piece by piece, always choosing the next piece that offers the most obvious and immediate benefit. So the problems where choosing locally optimal also leads to global solution are the best fit for Greedy. For example consider the Fractional Knapsack Problem.


1 Answers

What you are asking is how to decide whether a given system of coins is canonical for the change-making problem. A system is canonical if the greedy algorithm always gives an optimal solution. You can decide whether a system of coins which includes a 1-cent piece is canonical or not in a finite number of steps. Details, and more efficient algorithms in certain cases, can be found in http://arxiv.org/pdf/0809.0400.pdf.

like image 97
Edward Doolittle Avatar answered Oct 06 '22 01:10

Edward Doolittle