Questions tagged [partition-problem]

In computer science, the partition problem is to decide whether a given multiset of integers can be partitioned into two "halves" that have the same sum.

In computer science, the partition problem is an NP-complete problem. The problem is to decide whether a given multiset of integers can be partitioned into two "halves" that have the same sum. More precisely, given a multiset S of integers, is there a way to partition S into two subsets S1 and S2 such that the sum of the numbers in S1 equals the sum of the numbers in S2? The subsets S1 and S2 must form a partition in the sense that they are disjoint and they cover S.

The optimization version asks for the "best" partition, and can be stated as: Find a partition into two subsets S1,S2 such that max(operatorname{sum}(S_1), operatorname{sum}(S_2)) is minimized (sometimes with the additional constraint that the sizes of the two sets in the partition must be equal, or differ by at most 1).

The partition problem is equivalent to the following special case of the subset sum problem: given a set S of integers, is there a subset S1 of S that sums to exactly t /2 where t is the sum of all elements of S? (The equivalence can be seen by defining S2 to be the difference S − S1.) Therefore, the pseudo-polynomial time dynamic programming solution to subset sum applies to the partition problem as well.

A variation of the partition problem is the 3-partition problem, in which the set S must be partitioned into |S|/3 triples each with the same sum. In contrast to partition, 3-partition has no pseudo-polynomial time algorithm unless P = NP: 3-partition remains NP-complete even when using unary coding.

58 questions
2
votes
2 answers

algorithm for binary two-dimensional rectangular partitioning

We are doing a scheduler for heterogeneous computing. The tasks can be identified by their deadline and their data-rate and can be regarded as a two dimensional graph. See image: The rectangle identifies tasks to be scheduled on the GPU, and…
Sune1987
  • 25
  • 5
2
votes
3 answers

Partitioning By date column in Athena

I'm using AWS Athena to query S3 bucket, that have partitioned data by day only, the partitions looks like day=yyyy/mm/dd. When I tried to us Glue to run update the partitions every day, It creates new table for each day (sync 2017, around 1500…
Matan Stern
  • 21
  • 1
  • 3
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
1 answer

how print_parts() function work in composing program chapter2.3

in book composing program chapter 2.3, there is a function print_part() makes me confused (whole code here): >>> def print_parts(tree, partition=[]): if is_leaf(tree): if root(tree): print(' + '.join(partition)) …
2
votes
0 answers

Get the elements of subsets in Balanced Partition using Backpointers

I want to implement the Balanced Partition probelm and get the elements of the subsets using backpointers. I have a question about Backpointers: With the help of MIT's Dynamic Programming Practice Problems Nr. 7 and this example code, I managed to…
MrWeix
  • 397
  • 1
  • 6
  • 17
1
vote
1 answer

Create an int array of int arrays that contains all possible sums that add up to a given number

I'm completely new in Java. I am writing an Android game, and I need to generate an array of int arrays that contains all possible sums (excluding combinations that contains number 2 or is bigger than 8 numbers) that add up to a given number. For…
1
vote
0 answers

How can N integers be divided into M equally sized groups such that the difference between their maximum and minimum sums is minimum?

How can N integers be divided into M equally sized groups such that the difference between their maximum and minimum sums is minimum? I see that it belongs to the partition kind of problems, but I didn't find a solution that matches both "M > 2" and…
1
vote
4 answers

Split array into two even sets of integers, each so that both sets add up to the same number

I have had this problem for an interview and can't seem to wrap my mind around how to solve it. I have not found any tutorials that explains the logic behind it as well. Have the function ArrayChallenge(arr), take the array of integers stored in arr…
Nabreezy
  • 41
  • 1
  • 4
1
vote
0 answers

How to split a list of objects on the basis of two criteria in optimized way?

I have a list of objects say bag which has Quantity, Volume and weight. I want to split or join multiple object on the user input which will be max weight and max volume , So we want to split the list of bag further into more bag which has maximum…
1
vote
1 answer

Given list of integers, find the sets of numbers whose sum >= a target number, minimising the total amount that each set goes over the target

So somehow a relative of mine got these restaurant vouchers that can be used to deduct 500 baht off of each receipt. It is possible to ask the restaurant to issue multiple receipts so that multiple vouchers can be used. The relative wishes to spend…
patty
  • 313
  • 2
  • 8
1
vote
1 answer

Print Not Matching With An Array I'm Appending To

I'm trying to make a function that takes an array of numbers and gives you every combination those numbers can be in, in two arrays. My problem is that I can print the exact results that I want, but when I try to save the results into a variable,…
user10034548
1
vote
2 answers

Team creation algorithm via player preference

I'm making a matchmaking client that matches 10 people together into two teams: Each person chooses four people they would like to play with, ranked from highest to lowest. Two teams are then formed out of the strongest relationships in that…
SlickJava
  • 111
  • 1
  • 10
1
vote
1 answer

Partition algorithm without loop, only recursion

Given a list of integers. Find out whether it can be divided into two sublists with equal sum. The numbers in the list is not sorted. For example: A list like [1, 2, 3, 4, 6] will return true, because 2 + 6 = 1 + 3 + 4 = 8 A list like [2, 1, 8, 3]…
1
vote
1 answer

Variant of Knapsack

I'm working on a program to solve a variant of the 0/1 Knapsack problem. The original problem is described here: https://en.wikipedia.org/wiki/Knapsack_problem. In case the link goes missing in the future, I will give you a summary of the 0/1…
1
vote
1 answer

Recursively divide a list that each iteration divides into two parts to get the closest sum overall

Given a list of numbers L = { a1, a2, a3, a4, ... , aN} The problem is to divide this L into two parts, not just once but recursively until it becomes atomic. The main idea is like this post but adding the recursion thing. (added: June 9) For…