Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Combination Generator

Thread view: 
Scott Dudley - 28 Jun 2005 15:32 GMT
I need an algorithm that will, provided a set of decimal numbers,
identify any combination thereof that add up to N.  The size of the set
(array, list, etc.) is unknown.

Seems I recall seeing code for a combination generator in one of my
algorithm books (Sedgwick?) that would fit the bill.  Unfortunately, I'm
faced with a challenge at work and my books are at home.

Thanks.
Roedy Green - 28 Jun 2005 16:16 GMT
>Seems I recall seeing code for a combination generator in one of my
>algorithm books (Sedgwick?) that would fit the bill.  Unfortunately, I'm
>faced with a challenge at work and my books are at home.

see http://mindprod.com/jgloss/combination.html

Signature

Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes

Gordon Beaton - 28 Jun 2005 16:23 GMT
> I need an algorithm that will, provided a set of decimal numbers,
> identify any combination thereof that add up to N. The size of the
> set (array, list, etc.) is unknown.

This is a knapsack problem, a one-dimensional special case of bin
packing. You'll find lots of information, analysis and example code if
you google. AFAIK the problem is NP-complete.

Here's a good heuristic however, from memory:

Choose the largest of your remaining elements that fits in N, and
reduce N accordingly. Repeat until either N is 0, or there are no more
elements that are small enough.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

bugbear - 28 Jun 2005 17:24 GMT
> I need an algorithm that will, provided a set of decimal numbers,
> identify any combination thereof that add up to N.  The size of the set
[quoted text clipped - 3 lines]
> algorithm books (Sedgwick?) that would fit the bill.  Unfortunately, I'm
> faced with a challenge at work and my books are at home.

http://www.nuigalway.ie/mat/algorithms/knapsack.html

   BugBear


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.