Class Change
java.lang.Object
topics.greedy.Change
GREEDY ALGORITHM PROBLEM: THE PROBLEM OF THE CHANGE OF MONEY
It has an optimal solution in some cases.
The idea (heuristic) is always give the higher currency
value that is less than or equal to the amount left to
return
- Author:
- vicegd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcalculateCoins(double amount) Calculates the coins to be used to give a specific amount of money This method has a good complexity O(n)
-
Constructor Details
-
Change
public Change(float[] coins, int[] solution) Constructor for Change objects- Parameters:
coins- Available coins to be usedsolution- Array to save the number of coins of each type used as a solution
-
-
Method Details
-
calculateCoins
public void calculateCoins(double amount) Calculates the coins to be used to give a specific amount of money This method has a good complexity O(n)- Parameters:
amount- Amount of money that the needs to be given
-