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
5
votes
3 answers

correct me for using generators or tell me other way

I have A menu dict item as key and price as value. There may exist a combination of item that will be bit cheaper than single item. For exa: menu = { ('burger',) : 5.00, ('pizza',) : 12.00, ('coke',) : 4.00, ('macpuff',) : 4.00, …
Roshan
  • 1,459
  • 1
  • 14
  • 20
5
votes
3 answers

find a solution to subset sum using dynamic programming

What I want to do I want to find a subset of an array that sums to a target T. I also want to use to a dynamic programming approach (and a bottom-up solution at that) to do this. What I currently have Currently I only found a way to see if amongst…
Arnab Datta
  • 5,356
  • 10
  • 41
  • 67
5
votes
3 answers

Dynamic programming sum

How would you use dynamic programming to find the list of positive integers in an array whose sum is closest to but not equal to some positive integer K? I'm a little stuck thinking about this.
CyberShot
  • 2,265
  • 6
  • 28
  • 36
5
votes
3 answers

given a set of n integers, return all subsets of k elements that sum to 0

given a unsorted set of n integers, return all subsets of size k (i.e. each set has k unique elements) that sum to 0. So I gave the interviewer the following solution ( which I studied on GeekViewpoint). No extra space used, everything is done in…
kasavbere
  • 5,873
  • 14
  • 49
  • 72
4
votes
9 answers

Find the elements of an array based on minimum sum

I've written a loop in C++ to give me 6 random numbers and store them in an array. What I would like to do is to sum the elements of the array until I get a value larger than a number, "x", but I would like to do this without necessarily adding all…
user103572
  • 489
  • 1
  • 6
  • 9
4
votes
2 answers

Maximum subset sum with two arrays

I am not even sure if this can be done in polynomial time. Problem: Given two arrays of real numbers, A = (a[1], a[2], ..., a[n]), B = (b[1], b[2], ..., b[n]), (b[j] > 0, j = 1, 2, ..., n) and a number k, find a subset A' of A (A' = (a[i(1)], …
Geni
  • 687
  • 3
  • 10
  • 22
4
votes
2 answers

Algorithm to recover a set given the sums of all its subsets

There is a set A of positive/negative integers. We are given N numbers which are the sum of all its subsets. The task is to find the set A itself. Following is an example. Input: 0 -2 4 5 2 3 9 7 Output: A = {-2 4 5} For the case of positive…
fmatt
  • 464
  • 1
  • 5
  • 15
4
votes
1 answer

Finding the terms of a summation problem that need to be excluded to match the expected sum

I'm trying to automatize/speed up a control process. The best way to imagine this is like a little store: I know the total that's supposed to be left in the register at the end of the day (e.g. 150$), I have a list of sales, the sum of which should…
4
votes
4 answers

Dynamic Programming Maximum Profit for Movers in 2 cities

There is a moving company. It operates in two cities. They wish to maximize profit. Given are 2 arrays representing the two cities. The value at position i in each of the arrays indicates the maximum profit to be made in the city that day. If they…
lazycamper
  • 43
  • 1
  • 5
4
votes
1 answer

Power set solution in **O(n) time** and **O(n) space** complexities?

Is it possible to find all possible subsets of set in (i.e. power set) in O(n) time and O(n) space complexities? Program in put >> {a,b,c} Expected out put in O(n) time and O(n) space complexity, here n is 3. {}, {a}, {b}, {c}, {a,b}, {b,c},…
RiyasAbdulla
  • 171
  • 1
  • 12
4
votes
1 answer

Subset sum with negative numbers

So I have a given set C of n positive integers (c_1, ..., c_n). The task is to find two subsets A and B of C, where A contains only positive numbers and B contains only the negatives of the numbers in C. The sum of the two subsets A and B should…
G.M
  • 530
  • 4
  • 20
4
votes
3 answers

Recursion to find n numbers in a range that add up to a target value

I've written a function that finds all sets of two numbers that sum a target value, given a range of numbers from 0 to x. I'm trying to rewrite it in a way so that you can get a result of a given length n (not only 2), but n numbers that will equal…
Timothy Barmann
  • 598
  • 7
  • 17
4
votes
3 answers

Subset Sum with a list of 2675 numbers

I am looking for a yes/no answer to a question whether it can be solved with efficiency or not. I am pretty sure that's impossible with current state of computing technology available to us. I would be glad to know I am wrong. So here goes nothing.…
ishan
  • 73
  • 1
  • 2
  • 7
4
votes
4 answers

Subset Sum algorithm efficiency

We have a number of payments (Transaction) that come into our business each day. Each Transaction has an ID and an Amount. We have the requirement to match a number of these transactions to a specific amount. Example: Transaction Amount 1 …
anothershrubery
  • 20,461
  • 14
  • 53
  • 98
4
votes
3 answers

How can I build this tree with O(n) space complexity?

The Problem Given a set of integers, find a subset of those integers which sum to 100,000,000. Solution I am attempting to build a tree containing all the combinations of the given set along with the sum. For example, if the given set looked like…
jimpudar
  • 309
  • 2
  • 9