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
3
votes
1 answer

recursive function for subset sum problem with floating-point numbers

I made a recursion function f(s,x) for the subset sum problem, which is able to produce all unique combinations that sum up to the target sum 's' when picking elements from the set of values x. For example, assuming x <- c(2,4,8,10), and s <- 10…
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81
3
votes
1 answer

How to delete consecutive elements in a linked list which add up to 0

I'm writing a Python code to delete those consecutive elements in a linked list, which add up to 0 The linked list is defined as follows: class Node: def __init__(self, val, next=None): self.value = val self.next = next node =…
Vishrut Jha
  • 74
  • 1
  • 1
  • 9
3
votes
2 answers

Find possible solutions for a matrix with known row/column sums and maximum cell values

I am trying to find solutions to a matrix where I know the row and column sums and the maximum value a cell can have. I want to find possible solutions that are within the constraints. I've already tried various things like constructing an array of…
Splatbang
  • 756
  • 1
  • 12
  • 29
3
votes
1 answer

Return all subsets whose sum is a given value (subset sum problem)

The subset sum problem is the problem to create an algorithm that takes an array and sum and returns all subsets of the argument array whose sum is equal to the given sum. I am attempting to solve a variety of the subset sum problem (using…
K. Claesson
  • 603
  • 8
  • 22
3
votes
1 answer

Algorithm to find minimum number N to partition a stack's values in X subsets with sum lower than N

I have a stack with integer values objects. I want to buy a truck with capacity N( N is unknown) to be sure that I can transport all the objects in maximum X laps. X is known. In other words, I have to partition the stack( the order of objects…
3
votes
1 answer

Smallest monetary amount that can be obtained using only coins of specified denominations that exceeds a threshold

In other words, given a set of n positive integers A and a threshold B, I want to find the smallest C so that: C > B C = A[1] * k[1] + A[2] * k[2] + ... + A[n] * k[n], k[i] are integers >= 0 As an example if A = { 6, 11, 16 } then the values we…
3
votes
2 answers

SubSet sum with N array Solution, Dynamic Solution recquired

Though you can have any number of arrays but let's Suppose you have two arrays {1,2,3,4,5,6} and {1,2,3,4,5,6} You have to find whether they sum upto 4 with participation of both array elements. i.e. 1 from array1, 3 from array2 2 from array1, 2…
Suvam Roy
  • 963
  • 1
  • 8
  • 19
3
votes
2 answers

example about array in java

assume that i have an array int [] arr={1,2,4,5,7} and also have number 6 so i need the result to be 01100 that means that 2+4=6 in the array so the result will be 1 if the number in the sum 0 otherwise also i need number of bits in the result be…
3
votes
3 answers

Find all combinations of a given set of integers summing up to a given sum

I am looking for an answer to the following problem. Given a set of integers (no duplicates) and a sum, find all possible combinations of the set's elements summing up to the sum. Solutions order does not matter (solutions {2, 2, 3} and {3, 2 ,2}…
Dzik
  • 41
  • 1
  • 5
3
votes
2 answers

How would I calculate the worst case time complexity of this recursive function?

I don't believe this is efficient at all. I'm trying to create a faster implementation of this (preferably binary search or use of Sets perhaps), but for now this is where I'm at. I'm not sure if it's relevant, but I created a count variable just…
DevOpsSauce
  • 1,319
  • 1
  • 20
  • 52
3
votes
2 answers

Subsetting a list to add up to elements in another list

Does anyone have some thoughts on elegant code and math using python to solve the following problem? I have two lists of…
Chad Larson
  • 309
  • 2
  • 11
3
votes
5 answers

Partitioning a List in Prolog

I am trying to create a Prolog predicate where, given a list, it is seen whether or not the list can be split into two lists that sum to the same amount. I have a working list sum predicate, so I am using that within my partitioning predicate. I…
red_student
  • 316
  • 2
  • 6
  • 16
3
votes
1 answer

Decreasing the run time for my recursive subset sum algorthim

I have a recursive DFS algorithm that correctly counts the amount of subset sums there are. However, the run time for this method is absurd and extremely exponential. For example, when arr contains the set below. The sum we are looking for is 50.…
user3328187
  • 193
  • 2
  • 2
  • 6
3
votes
1 answer

Compare a Number with sum of subset of numbers

I am looking a guidance of your gurus to find out a way to Compare a Number with a sum of subset of numbers like DECLARE L_NUM_TO_COMPARE NUMBER := 0; L_NUM_SUBSET NUMBER := 0; BEGIN FOR MAIN_REC IN ( SELECT 1 ID, 25150 …
alhashmiya
  • 169
  • 1
  • 5
  • 16
3
votes
1 answer

Optimizing Kadane's Algorithm for numpy

The standard way to find the maximum subarray is Kadene's algorithm. If the input is a large numpy array, is there anything faster than the native python implementation? import timeit setup = ''' import random import numpy as np def…
Hooked
  • 84,485
  • 43
  • 192
  • 261