subset-sum


Subset whose sum is the smallest sum over a specific threshold


Given a collection of positive integers, I want the subset of those integers whose sum is the smallest sum that exceeds a threshold.
Your problem is a variation on the Subset Sum Problem and is NP-complete.
To see why, let's assume that you have an algorithm that can solve your problem and it produces an answer with sum s. Then you have proven that there exists no subset of the integers that equals s - 1, i.e. you have a solution to the subset sum problem.
If performance is not an issue, you might as well just enumerate all possible sets. If performance is an issue, you could try looking on the Wikipedia page for ideas on how to optimize this sort of algorithm, such as by using dynamic programming. The algorithm on that page should in fact solve your problem almost as efficiently as the subset sum problem.
"smallest sum": there's a classical "max sum" problem, described well here: http://wordaligned.org/articles/the-maximum-subsequence-problem
This is just a tiny variation with a "exceeds a threshold" condition - just an extra IF statement in your loop.
I had the same problem! If all N integers are positive and are bounded by a constant C, then there is a solution, with time and space requirements of O(NC).
Pisinger discovered a linear-time dynamic programming algorithm to find the maximum value under a threshold, which is like the inverse of your problem. So, if you subtract your desired threshold from the total sum of the integers, you can use this new threshold with Pisinger's algorithm to find all the numbers NOT in the desired set.
Depending on the size of the integers in question, this may or may not be feasible.
Pisinger's paper:
http://www.diku.dk/~pisinger/95-6.ps
Code:
Fast solution to Subset sum algorithm by Pisinger

Related Links

Subset sum with dynamic programming
Reducing Subset Sum Problm
Clarification on subset sum
Subset whose sum is the smallest sum over a specific threshold

Categories

HOME
vbscript
reserved
plot
iot
kalman-filter
jsp-tags
google-oauth
icloud
retrofit
ravendb
yum
pivotal-cloud-foundry
ios-charts
facebook-messenger-bot
django-simple-history
normalizr
introduction
one-hot-encoding
ehcache
telerik-reporting
blazemeter
kendo-datasource
objectanimator
gsoap
sql-server-2012-express
phonegap
ioio
create-table
contact-form
commit
wixsharp
elasticsearch-plugin
dism
android-tabhost
avro4s
isbn
qcombobox
btrace
outlook-2013
strptime
zip4j
datastax-startup
togetherjs
libusb-win32
media-player
watchconnectivity
setuptools
skobbler-maps
jwplayer7
angstrom-linux
markojs
whois
captivenetwork
iad
collapse
fouc
responsive-images
vstest.console.exe
sniffer
apache-commons-net
camanjs
qpainter
javafx-webengine
socketexception
system.net.webexception
fmod
orchardcms-1.7
enterprisedb
wsdl-2.0
trusted
objective-c-2.0
parametric-equations
appconkit
assembly-loading
gnustep
coredump
f#-powerpack
xtype
javax.script
servicehost
site.master
user-friendly
zend-tool
exchange-server-2003
mtj
procedural-music
port-number
private-members
multiple-languages

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App