image
Physics Forums Logo
image
image
* Register * Upgrade Blogs Library Staff Rules Mark Forums Read
image
image   image
image

Go Back   Physics Forums > Mathematics > General Math


Reply

image Greedy algorithm Share It Thread Tools Search this Thread image
Old Oct4-06, 01:41 AM                  #1
CRGreathouse

CRGreathouse is Offline:
Posts: 3,097
Recognitions:
Homework Helper Homework Helper
Science Advisor Science Advisor
Greedy algorithm

I'm not sure that this is the right place for this post, but I couldn't find a better.

Many years ago I considered the problem of making change with (say) quarters, dimes, nickels, and pennies. I tried to prove to myself that what I now call the greedy algorithm (pick the most valuable coin that doesn't take you over your limit) always made optimal change -- that no solutions with fewer coins existed. At the time I wasn't able to find a proof of the specific case {25, 10, 5, 1} but I could see that the general result failed -- consider {5, 4, 1} to make a total of 8 cents. The greedy algorithm gives (5, 1, 1, 1) but (4, 4) is better.

I was wondering if there's a good characterization of what combination of coin values make the greedy algorithm always optimal. Back then I could see that being in a geometric series was a sufficient, but unnecessary, condition. Briefly reconsidering the problem, it seems that the greedy algorithm should be optimal for superincreasing sequences -- but is this necessary for optimality? Any thoughts, counterexamples, or reading/references?
  Reply With Quote
Old Oct4-06, 02:37 AM       Last edited by Hurkyl; Oct4-06 at 02:40 AM..            #2
Hurkyl

PF Mentor
 
Hurkyl's Avatar

Hurkyl is Online:
Posts: 13,363
This is certainly a classical problem. A quick search turns up this:

http://mathforum.org/wagon/spring04/p1009.html

(but I can't seem to follow the link contained in it. I don't think you could get the text easily from there anyways)

which makes it sound like a necessary and sufficient condition won't be simple to write. I know there are some nice, simple, sufficient conditions, but I can't remember the usual one, and I think my only hard reference is at work.


edit: I think this is the paper on it. (You can grab it from the "cached: ... PDF" link in the top-right corner) It doesn't seem terribly clear, but maybe I'm just tired.
  Reply With Quote
Old Oct4-06, 03:26 PM                  #3
CRGreathouse

CRGreathouse is Offline:
Posts: 3,097
Recognitions:
Homework Helper Homework Helper
Science Advisor Science Advisor
Originally Posted by Hurkyl
edit: I think this is the paper on it. (You can grab it from the "cached: ... PDF" link in the top-right corner) It doesn't seem terribly clear, but maybe I'm just tired.
Thanks a bunch, that's exactly what I was hoping for I'll read through it and see how much I get. I appreciate it!
  Reply With Quote
Old Oct4-06, 05:10 PM       Last edited by CRGreathouse; Oct4-06 at 05:17 PM..            #4
CRGreathouse

CRGreathouse is Offline:
Posts: 3,097
Recognitions:
Homework Helper Homework Helper
Science Advisor Science Advisor
Well, I read the paper. It shows that it can be decided in polynomial time (O(n^2)) if a certain combination of coin values can always be solved optimally with the greedy algorithm, even though determining the least number of coins needed for a given set of coin values and total x is NP-hard.

Also, I was able to find a counterexample to my 'conjecture' above. Not all superincreasing sequences are solved optimally by the greedy algorithm; consider coins {2001, 1000, 1} and total 3000. I'll see if I can find the least superincreasing counterexample now -- clearly, it has exactly 3 coins.

Edit: I think it's {6, 4, 1} with a total of 8.
  Reply With Quote
image image
Reply
Thread Tools


Similar Threads for: Greedy algorithm
Thread Thread Starter Forum Replies Last Post
help with greedy algortitm please!! steve22 Engineering, Comp Sci, & Technology 1 Jul22-07 04:53 PM
algorithm hyderman Calculus & Beyond 1 Jan19-07 09:45 PM
Welfare recipients getting greedy Rach3 General Discussion 1 Jun28-06 10:17 PM
Shaming the greedy Loren Booda General Discussion 12 Sep2-05 12:39 PM
a new algorithm? nash_81 General Math 2 Aug13-04 04:06 AM

Powered by vBulletin Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. © 2009 Physics Forums
Sciam | physorgPhysorg.com Science News Partner
image
image   image