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
log4j
winforms
hook
reflection
c#-4.0
deezer
reserved
rsync
setup-deployment
yahoo-oauth
razor
append
amazon-cloudformation
slick-slider
primary-key
windows-10-universal
adobe-analytics
google-cloud-ml
gz
quickfix
dynamics-crm-online
reactcsstransitiongroup
normalizr
karma-jasmine
scichart
crosstab
android-widget
opennlp
lightswitch-2013
stormpath
http-status-code-503
contact-form
jspresso
noraui
language-concepts
nssegmentedcontrol
ios5
vxworks
x11-forwarding
lto
libraries
reportbuilder
unobtrusive-validation
webdriver-manager
preconditions
galen
janrain
google-closure
outlook-api
unixodbc
skeleton-css-boilerplate
azure-application-gateway
upstart
multipeer-connectivity
hendrix
integrity
idisposable
drupal-6
libusb-win32
cudafy.net
iso8601
topbeat
google-cdn
color-picker
android-textview
sts-springsourcetoolsuite
mathematica-frontend
clang-static-analyzer
prettytensor
bluemix-app-scan
rhino-servicebus
freedesktop.org
browser-bugs
arcanist
sysinternals
web-controls
jscript.net
tablelayout
terminfo
expected-exception
ember-charts
java.nio.file
.aspxauth
android-screen-support
drools-planner
robotics-studio
dmoz
jquery-knob
rdoc
frameset
chrono
amazon-appstore
recent-documents
calling-convention
sql-server-profiler
imac
wise
xsdobjectgen
nhibernate.search
ext3
backcolor
eqatec
ubuntu-9.04
.net-1.0
paul-graham
uiq3

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