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
gitlab
cookies
angular-material
json.net
iot
razor
elm
ckeditor
convolution
portia
webrequest
basic
quickfix
worldwind
serilog
facebook-instant-articles
qhull
cas
bootstrap-duallistbox
fluentvalidation
windows-server-2000
srcset
madlib
lightswitch-2013
contact-form
grails-3.1
kendo-ui-grid
geopositioning
picasso
io-redirection
git-merge
bitbucket-pipelines
xenforo
ibpy
unixodbc
gpx
babel-core
skeleton-css-boilerplate
auto-update
angular-resource
osx-mavericks
parentheses
youcompleteme
powercli
sqlbulkcopy
python-cryptography
pillow
sqldf
spring-mongodb
minimization
chord-diagram
word-vba-mac
time-and-attendance
visual-c++-2008
sts-springsourcetoolsuite
fody
transmitfile
firebaseui
skype4py
whois
pickadate
netmq
browser-link
execute
prerequisites
angular-leaflet-directive
ionic
appfabric-cache
census
directoryservices
nsbutton
applescript-objc
wordpress-theme-customize
java-metro-framework
navigationservice
dealloc
commoncrypto
ftps
sabredav
ocunit
anonymous-methods
simba
nsnetservice
google-email-migration
amazon-appstore
transactionscope
datareader
fluent-interface
blitz++
asp.net-mvc-areas
paster
wise
adrotator
virtual-functions
boost-smart-ptr
anti-piracy

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App