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
109
votes
6 answers

1D Number Array Clustering

So let's say I have an array like this: [1,1,2,3,10,11,13,67,71] Is there a convenient way to partition the array into something like this? [[1,1,2,3],[10,11,13],[67,71]] I looked through similar questions yet most people suggested using k-means…
E.H.
  • 3,271
  • 4
  • 19
  • 18
30
votes
3 answers

Better results in set partition than by differencing

Partition problem is known to be NP-hard. Depending on the particular instance of the problem we can try dynamic programming or some heuristics like differencing (also known as Karmarkar-Karp algorithm). The latter seems to be very useful for the…
kuszi
  • 2,069
  • 29
  • 36
14
votes
8 answers

3-PARTITION problem

here is another dynamic programming question (Vazirani ch6) Consider the following 3-PARTITION problem. Given integers a1...an, we want to determine whether it is possible to partition of {1...n} into three disjoint subsets I, J, K such that sum(I)…
user467871
10
votes
6 answers

Getting all possible sums that add up to a given number

I'm making an math app for the android. In one of these fields the user can enter an int (no digits and above 0). The idea is to get all possible sums that make this int, without doubles (4+1 == 1+4 in this case). The only thing known is this one…
Manuel
  • 10,153
  • 5
  • 41
  • 60
10
votes
5 answers

divide list in two parts that their sum closest to each other

This is a hard algorithms problem that : Divide the list in 2 parts (sum) that their sum closest to (most) each other list length is 1 <= n <= 100 and their(numbers) weights 1<=w<=250 given in the question. For example : 23 65 134 32 95 123…
user467871
7
votes
3 answers

Problems with dynamic programming

I've got difficulties with understanding dynamic programming, so I decided to solve some problems. I know basic dynamic algorithms like longest common subsequence, knapsack problem, but I know them because I read them, but I can't come up with…
xan
  • 1,053
  • 1
  • 10
  • 29
7
votes
3 answers

Recursive-backtracking algorithm for solving the partitioning problem

Hey, i'm looking for some help to find an algorithm which divides an array of positive numbers into k-parts so that each part has the (approximately) the same sum ... let's say we have 1,2,3,4,5,6,7,8,9 en k=3 thn the algorithm should partition it…
6
votes
2 answers

Explanation for appropriate partition-counting algorithm?

I've been working through some algorithm programming problems and have a question about one. The problem is the same one as the one referenced in this question: USACO: Subsets (Inefficient) I was able to code some (non-dynamic) solutions that were…
Herbert Sitz
  • 21,858
  • 9
  • 50
  • 54
5
votes
4 answers

Print all unique integer partitions given an integer as input

I was solving a programming exercise and came across a problem over which I am not able to satisfactorily find a solution. The problem goes as follows: Print all unique integer partitions given an integer as input. Integer partition is a way of…
4
votes
6 answers

Need idea for solving this algorithm puzzle

I've came across some similar problems to this one in the past, and I still haven't got good idea how to solve this problem. Problem goes like this: You are given an positive integer array with size n <= 1000 and k <= n which is the number of …
Mike Plott
  • 327
  • 1
  • 2
  • 6
3
votes
1 answer

How to reconstruct partitions in the Karmarkar-Karp heuristic multi-way partitioning algorithm?

I'm trying to implement the k-partitioning version of the Karmarkar-Karp heuristic number partitioning algorithm. But I'm struggling with its second phase where number partitions are reconstructed from the resulting difference-set. The only source…
3
votes
1 answer

SHORTEST delivery time by 2 transporters

I am dealing with an algorithmic problem. I have a known graph algorithm with a single central node. The aim is to deliver goods from this central node to some other, specified nodes by TWO transporters. Every transporter can carry max. one unit of…
3
votes
2 answers

Divide a given set of numbers N in two groups such that their difference of their sum is minimum?

You can exempt atmost one element from the set to acheive the goal. example:- N=3 the numbers given are = 1,2,5 So, Set 1 should be :- [1] Set 2 should be :- [2] We have excluded 5 as we can acheive a lesser difference without it being in either…
azero0
  • 2,220
  • 3
  • 20
  • 31
3
votes
1 answer

Dividing set of integers

I've got a problem with a solution for algorithmic problem as described below. We have a set (e.g. array) of integers. Our task is to divide them into the groups (they don't have to have same amount of elements) that sum is equal to each other. I…
2
votes
2 answers

Postgres partition pruning

I have a large table in Postgres. The table name is bigtable and the columns are: integer |timestamp |xxx |xxx |...|xxx category_id|capture_time|col1|col2|...|colN I have partitioned the table on modulo 10 of category_id and date part of the…
Dojo
  • 5,374
  • 4
  • 49
  • 79
1
2 3 4