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
1
vote
2 answers

Determine if there is a 3-partition given n numbers using Dynamic Programming

I found a solution to the 3-partition problem, that is, given n numbers, you determine if you can form three (disjoin) subsets such that all are equal (that is, each subset has a sum equal to the sum of the n numbers/3). A similar question is at:…
user678392
  • 1,981
  • 3
  • 28
  • 50
1
vote
1 answer

Which algorithm can be used to solve this variation of the partition-prob?

This is the problem: You have two arrays A and B, of equal length. You have to partition them into two groups P and Q such that: (1) Their difference is minimized. (2) If A[i] goes into one of P or Q, B[i] should go into another. Here is a link to…
2147483647
  • 1,177
  • 3
  • 13
  • 33
1
vote
3 answers

Partitioning an Integer into 9 non-negative integers with limits

There's an equation: 1a + 2b + 3c + 4d ... + 9i = 9 Constraints: 1 <= a + b + c + ... + i <= 104 where a,b,..,i are non-negative integers and each of the integers have a particular range. For example: 1 <= a <= 5, 2 <= b <= 3, and so on. I need to…
ryanwilson
  • 39
  • 3
1
vote
1 answer

Divide list into two equal parts algorithm

Related questions: Algorithm to Divide a list of numbers into 2 equal sum lists divide list in two parts that their sum closest to each other Let's assume I have a list, which contains exactly 2k elements. Now, I'm willing to split it into two…
1
vote
1 answer

conjugate of an integer partition

Is the conjugate of an integer partition, selected at random from the set of all partitions for n, also a uniform random sample? My results suggest yes, which is encouraging for the sake of quickly generating random partitions of n that are of…
klocey
  • 314
  • 5
  • 12
0
votes
2 answers

Matlab matrix partitioning

I would like to partition a matrix by an approximate even amount of rows. For example, if I have a matrix by these dimensions 155 x 1000, how can I partition it by 10 where each new matrix has the approximate dimensions 15 X 1000?
lurodrig
  • 99
  • 3
  • 8
0
votes
1 answer

Contiguous subarray and non-Contiguous

I was trying to solve this problem on leetcode. You are given a 0-indexed integer array nums. You have to partition the array into one or more contiguous subarrays. We call a partition of the array valid if each of the obtained subarrays satisfies…
0
votes
0 answers

Radioactively Depleting timer list

I have a dataset of about 1-10k records, each has a ticking timer associated with it. I'd like to be able to query it in a way that it surfaces the data which has passed a certain time limit. Here's an example: [obj1] [2sec] [obj2] [3sec] [obj3]…
0
votes
0 answers

Given an array and group them as a possible sum

Given an array and group them as a possible sum. Input Only this array : [1,2,3,4,5] Output : {[5,1] [4,2]} {[3,2] [4,1]} Is there any way to solve this problem without using nesting of for loop?
Alok Tripathi
  • 874
  • 10
  • 9
0
votes
3 answers

How to partition combinations from three categories?

I have an array with recipes from 3 categories, breakfast, lunch and dinner. Each of these categories, have 10 unique recipes. $recipes = [ 'breakfast' => [ 0 => [ 'title' => 'eggless waffles', 'calorie' => 210, …
Stark
  • 572
  • 10
  • 24
0
votes
2 answers

Given an array of integers, create partitions where the sum of elements in every partition is 0 and maximum no of partitions are formed

My rules: Duplicates are allowed negative numbers are allowed obviously Since i mentioned partition, it means you cannot put an element from the array in more than 1 partition Elements in partition are subsets/need not be contiguous chunks of…
nishant_boro
  • 374
  • 1
  • 2
  • 8
0
votes
1 answer

Subset sum problem where each number can be added or subtracted

Given a set A containing n positive integers, how can I find the smallest integer >= 0 that can be obtained using all the elements in the set. Each element can be can be either added or subtracted to the total. Few examples to make this clear. A = […
rohit89
  • 5,745
  • 2
  • 25
  • 42
0
votes
2 answers

Creating a partition of a set in Scheme

I'm pretty new to scheme overall and I'm having some issues with figuring out an assignment for school. So please no full answers, just looking for a little insight or a nudge in the right direction so I can figure this out on my own. The problem…
Neil Ruggiero
  • 330
  • 3
  • 4
  • 11
0
votes
1 answer

Partition solution too slow

I am solving a problem that looks like partition problem to me: I have a sequence of integers and I should find one (if there are more than one solution I am supposed to output only single one) subset of these integers such that sum of them is…
user1505497
  • 321
  • 5
  • 13
0
votes
0 answers

Partition-P roblem with discontinuous subsets

I'm trying to solve a variant of the partition problem. I have two important twists. I need to solve for k partitions, not just 2, as in the classic partition problem. The following code does that: https://gist.github.com/ishikawa/21680 I also…
Adam
  • 913
  • 1
  • 9
  • 26