packbat: A bat wearing a big asexual-flag (black-gray-white-purple) backpack. (Default)
packbat ([personal profile] packbat) wrote2007-07-25 02:32 pm
Entry tags:

[identity profile] active-apathy.livejournal.com 2007-07-26 02:44 am (UTC)(link)
*nodnods* It is. It's a fairly trivial example, but it is nonetheless.

[identity profile] roaminrob.livejournal.com 2007-07-27 04:41 pm (UTC)(link)
How?

Change-making -- in the U.S. at least -- is trivial because the greedy approximation algorithm works perfectly every time. That particular algorithm works perfectly every time because there isn't the kind of overlap in units of money that you would find in, say, a geometric packing problem.

F'rinstance, for any amount of change to be dispensed, you start with quarters. Add quarters until you can't add any more. Next add dimes. Then nickels. Finish it off with pennies.

That can be done in linear time, because it requires no back-tracking, or recursion.

[identity profile] packbat.livejournal.com 2007-07-29 09:59 pm (UTC)(link)
That's true. I guess I was mixing it up with the problem I had in my head, which was: given a particular price, what is the optimal amount to pay so that the number of units – paid plus change – is a minimum.

Which, now that I think of it, might not even be NP. What was the definition again?

[identity profile] roaminrob.livejournal.com 2007-07-30 02:07 am (UTC)(link)
That's true. I guess I was mixing it up with the problem I had in my head, which was: given a particular price, what is the optimal amount to pay so that the number of units – paid plus change – is a minimum.

I don't think I understand you here. I did double-check the description of the change-making problem, and it looks like it's only talking about reaching an arbitrary exact sum, with the fewest coins possible, given a set of arbitrary denominations of money. So, you need to give me $US .83 in change, how do you do that using as few coins as possible?

(There's a good, though somewhat technical, paper at http://citeseer.ist.psu.edu/pearson94polynomialtime.html (http://citeseer.ist.psu.edu/pearson94polynomialtime.html).)

The change-making problem can be NP hard in some coin systems. For example, if you had a coin system with a 10-cent coin, a 1-cent coin, and a 6-cent coin, what's the optimal solution for 12 cents? The greedy approximation algorithm would give a dime and two pennies, when what you really want is two 6-cent coins. U.S. money doesn't break down like that though.

Which, now that I think of it, might not even be NP. What was the definition again?

Postde reply to my journal. (http://roaminrob.livejournal.com/50973.html)