Questions tagged [subset-sum]

In computer science, the subset sum problem is one of the important problems in complexity theory and cryptography.

In computer science, the subset sum problem is one of the important problems in complexity theory and cryptography.

424 questions
2
votes
2 answers

Is this an NP problem?

first off I'm going to say I don't know a whole lot about theory and such. But I was wondering if this was an NP or NP-complete problem. It specifically sounds like a special case of the subset sum problem. Anyway, there's this game I've been…
Earlz
  • 62,085
  • 98
  • 303
  • 499
2
votes
1 answer

equal k subsets algorithm

does anyone know a good and efficient algorithm for equal k subsets algorithm ? preferably c or c++ which could handle a 100 element vector maybe with a complexity and time estimation ex. 9 element vector x = {2,4,5,6,8,9,11,13,14} i need to…
john Stilkowicz
  • 297
  • 1
  • 5
  • 12
2
votes
2 answers

Time Complexity of Subset-Sum Enumeration

Normally, when dealing with combinations, the Big-O complexity seems to be O(n choose k). In this algorithm, I am generating all the combinations within the array that match the target sum: def combos(candidates,start, target): if target == 0: …
ApathyBear
  • 9,057
  • 14
  • 56
  • 90
2
votes
3 answers

JavaScript - Special case of subset sum algorithm

From a given array of positive integers, I want to know if the sum of E elements from the array is equal to a given number N. For example, given the array arr = [1, 2, 3, 4] , e = 3 and n = 9. It means if the sum of 3 elements in arr equals to 9.…
forkfork
  • 415
  • 6
  • 22
2
votes
2 answers

wrong Subset sum in O(n^2)

I know this code/logic is wrong for solving the subset sum problem, but can't seem to understand why. Calculate the sum of all possible subsets and check if any is equal to the required sum. This would be done in O(n^2) which is obviously wrong as I…
someone1
  • 115
  • 1
  • 11
2
votes
1 answer

If there is no subset sum equal to a given value, return subset sum closest to the value

I am working on a subset sum problem, that needs to print the subset sum that's closest to the value, if equal then just print the value. Only positive integers If there are multiple subset sums that are equally close to the value, value = 10,…
user33232
  • 63
  • 5
2
votes
2 answers

Use dynamic programming to find a subset of numbers whose sum is closest to given number M

Given a set A of n positive integers a1, a2,... a3 and another positive integer M, I'm going to find a subset of numbers of A whose sum is closest to M. In other words, I'm trying to find a subset A′ of A such that the absolute value |M - Σ a∈A′|…
2
votes
1 answer

Subset sum variation

Given an integer n and s sets of different sizes, but with positive ascending numbers from 0 to s_i as elements. Let a good sum be defined here as a_1 + a_2 + ... + a_s = n. Count how many sums are existent, when you take for every a_i an element…
2
votes
3 answers

Finding max value of a weighted subset sum of a power set

I've got a sparse power set for an input (ie some combos have been pre-excluded). Each entry in the power set has a certain score. I want to find the combination that covers all points and maximizes the overall score. For example, let's say the…
2
votes
2 answers

Finding maximum valued subset in which PartitionProblem algorithm returns true

I´ve got the following assignment. You have a multiset S with of 1<=N<=22 elements. Each element has a positive value of up to 10000000. Assmuming that there are two subsets s1 and s2 of S in which the sum of the values of all the elements of one is…
2
votes
2 answers

Improving this subset sum algorithm for a sequential range without using recursion

Given a min & max I'd like to find every combination of numbers in that range that add up to a given total using a specified number of bins (reusing numbers is OK). # of bins will approach but not exceed 32, so bitwise is awesome if that's an…
Matt K
  • 4,813
  • 4
  • 22
  • 35
2
votes
1 answer

Subset sum with binary numbers

I got X binary numbers of length Y and want to see if they add up to a specific sum K. I did some research on dynamic solutions for subset sum problems; however, I think this specific problem presents a twist. Adding two binary numbers with length…
RasmusJ
  • 396
  • 1
  • 2
  • 10
2
votes
1 answer

NP-Complete Reduction for Subset Sum

I'm studying for a final exam and one of the practice problems given to us from a past exam is as follows: My instinct says to reduce this problem to the Subset Sum problem. My initial solution is: Let 'A' be the Subset Sum NP-Complete…
KrispyK
  • 235
  • 6
  • 18
2
votes
2 answers

Recursion, multiple base cases in VBA

I'm trying to take the first block of code from this link: http://www.geeksforgeeks.org/dynamic-programming-subset-sum-problem/ Copied and pasted below: bool isSubsetSum(int set[], int n, int sum) { // Base Cases if (sum == 0) return…
AdamY
  • 851
  • 2
  • 9
  • 20
2
votes
1 answer

Subset sum with positive and negative integers

I've to implement a variation of the subset sum problem, my input will be positive and negative decimal, also I will need to know the subset, knowing that exists unfortunately it's not enough. I've tried the algorithms found on wikipedia, but I…
user3633705
  • 31
  • 1
  • 2