A vending machine is designed to return change in the following way:
Keep returning the coin with the largest denomination smaller than or equal to the remaining amount until all of the change has been returned.
However, this approach doesn't always yield the least number of coins. With the denominations 10, 40, and 50 cents, which of the following changes (in cents) could be returned using fewer coins than what the algorithm requires?
As an explicit example of the algorithm, when required to produce a 110 cents change, the vending machine would return the coins 50, 50, 10 cents, in that order.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Since the algorithm requires that the denomination always be smaller than the remaining amount, all of the change will never be returned and all answers are correct. Had the algorithm stated "the largest denominator equal to or less than the remaining amount," 120 would be the correct answer.
Log in to reply
Thanks. I've made that corresponding edit. Note that if we're forced to always use "denomination that is strictly smaller than the remaining amount", then this algorithm would never end.
The problem is not updated.
Thanks. I've updated the options accordingly.
The proposition of the problem is very vague and convoluted!
Log in to reply
Which part do you find vague/convoluted?
How do you think it can be improved on?
50+40 had fewer coins than 40+40+40. Why is 90 not the answer?
Log in to reply
I think you are interpreting the question as "Which amount requires the smallest number of coins?" in which case the answer would be 90, because it only requires 2 coins.
However, the question asks for the amount for which the described algorithm does not give optimal results. Out of the given choices, only 120 does not give optimal results, as shown by Judy in the solution. The algorithm returns 4 coins, but it is possible to make 120 with just 3 coins.
why can't it be 150? 50,50,50 ...
or 50+50+10+10+10+10+10
Log in to reply
Because the question asks for an amount that could return FEWER coins than the algorithm calls for.
Why is not 90 the answer? I don't find it clear enough.
Log in to reply
For 90, the vending machine gives you 50 and 40. Can you do better than that?
Log in to reply
As there are many confusions about your problem's text I think you should explain it better so that everybody else would be able to do better than that.
Why is 90 not an answer?
Algorithm: 50 + 10 + 10 + 10 + 10 Alternative: 50 + 40
Log in to reply
The algorithm also gives 50 + 40. Why would the algorithm give 50 + 10 + 10 + 10 + 10?
Log in to reply
Ah I see, I misunderstood the question because of the diagram. I thought that initially, the machine can only give out 50 and 10 cents and 40 is added later. Turns out that 40 was part of the original algorithm.
Log in to reply
@Soumil Sahu – It's alright. The image illustrates the example where it has to give 110 cents as change.
Could it be clearer (maybe in the example) that 40 cents is a coin denomination? Since we don't have 40-cent coins in the US and I was being ethnocentric, I had to think more about what "the denominations 10, 40, and 50 cents," meant in order for me to come up with the right answer since I was just assuming half-dollars, quarters, dimes, and nickels.
Log in to reply
This. I suppose there exists a 40¢ denomination in many parts of the world, such as Malaysia (the author's home). However, the dead giveaway was the problem's mention of a 50¢ coin (a rarity in the US). I guess this is a good incentive to knowing international currencies!
Log in to reply
40 cents is not a coin denomination in Malaysia either xD. It was being set this way for the purpose of this problem.
Log in to reply
@Christopher Boo – Like when math problems say "You can only buy watermelons in batches of 5 or 7 ..."
Problem Loading...
Note Loading...
Set Loading...
Algorithm: 120 = 50 + 50 + 10 + 10
Alternative with fewer coins: 120 = 40 + 40 + 40