The 3-partition problem is a
strongly NP-complete problem in
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includin ...
. The problem is to decide whether a given
multiset
In mathematics, a multiset (or bag, or mset) is a modification of the concept of a set that, unlike a set, allows for multiple instances for each of its elements. The number of instances given for each element is called the multiplicity of that ...
of integers can be partitioned into triplets that all have the same sum. More precisely:
* The input to the problem is a multiset ''S'' of ''n'' = 3 positive integers. The sum of all integers is .
* The output is whether or not there exists a partition of ''S'' into ''m'' triplets ''S''
1, ''S''
2, …, ''S''
''m'' such that the sum of the numbers in each one is equal to ''T''. The ''S''
1, ''S''
2, …, ''S''
''m'' must form a
partition of ''S'' in the sense that they are
disjoint and they
cover ''S''.
The 3-partition problem remains strongly NP-complete under the restriction that every integer in ''S'' is strictly between ''T''/4 and ''T''/2.
Example
# The set
can be partitioned into the four sets
, each of which sums to ''T'' = 90.
# The set
can be partitioned into the two sets
each of which sum to ''T'' = 15.
# (every integer in ''S'' is strictly between ''T''/4 and ''T''/2):
, thus ''m''=2, and ''T''=15. There is feasible 3-partition
.
# (every integer in ''S'' is strictly between ''T''/4 and ''T''/2):
, thus ''m''=2, and ''T''=15. There is no feasible solution.
Strong NP-completeness
The 3-partition problem remains NP-complete even when the integers in ''S'' are bounded above by a polynomial in ''n''. In other words, the problem remains NP-complete even when representing the numbers in the input instance in unary. i.e., 3-partition is NP-complete in the strong sense or
strongly NP-complete. This property, and 3-partition in general, is useful in many reductions where numbers are naturally represented in unary.
3-Partition vs Partition
The 3-partition problem is similar to the
partition problem In number theory and computer science, the partition problem, or number partitioning, is the task of deciding whether a given multiset ''S'' of positive integers can be partitioned into two subsets ''S''1 and ''S''2 such that the sum of the numbers ...
, in which the goal is to partition ''S'' into two subsets with equal sum, and the
multiway number partitioning In computer science, multiway number partitioning is the problem of partitioning a multiset of numbers into a fixed number of subsets, such that the sums of the subsets are as similar as possible. It was first presented by Ronald Graham in 1969 in t ...
, in which the goal is to partition ''S'' into ''k'' subsets with equal sum, where ''k'' is a fixed parameter. In 3-Partition the goal is to partition ''S'' into ''m'' = ''n''/3 subsets, not just a fixed number of subsets, with equal sum. Partition is "easier" than 3-Partition: while 3-Partition is
strongly NP-hard, Partition is only
weakly NP-hard - it is hard only when the numbers are encoded in non-unary system, and have value exponential in ''n''. When the values are polynomial in ''n'', Partition can be solved in polynomial time using the
pseudopolynomial time number partitioning In computer science, pseudopolynomial time number partitioning is a pseudopolynomial time algorithm for solving the partition problem.
The problem can be solved using dynamic programming when the size of the set and the size of the sum of the int ...
algorithm.
Variants
In the unrestricted-input variant, the inputs can be arbitrary integers; in the restricted-input variant, the inputs must be in (''T''/4 '', T''/2). The restricted version is as hard as the unrestricted version: given an instance ''S
u'' of the unrestricted variant, construct a new instance of the restricted version
''Sr'' ≔ . Every solution of ''S
u'' corresponds to a solution of ''S
r'' but with a sum of 7 instead of ''T'', and every element of ''S
r'' is in which is contained in .
In the distinct-input variant, the inputs must be in (''T''/4 '', T''/2), and in addition, they must all be distinct integers. It, too, is as hard as the unrestricted version.
In the unrestricted-output variant, the ''m'' output subsets can be of arbitrary size - not necessarily 3 (but they still need to have the same sum ''T''). The restricted-output variant can be reduced to the unrestricted-variant: given an instance ''S
u'' of the restricted variant, construct a new instance of the unrestricted variant
''Sr'' ≔ , with target sum 7. Every solution of ''S
u'' naturally corresponds to a solution of ''S
r''. In every solution of ''S
r'', since the target sum is 7 and each element is in , there must be exactly 3 elements per set, so it corresponds to a solution of ''S
u''.
The 4-partition problem is a variant in which ''S'' contains ''n'' = 4 integers, the sum of all integers is , and the goal is to partition it into ''m'' quadruples, all with a sum of ''T''. It can be assumed that each integer is strictly between ''T''/5 and ''T''/3.
The ABC-partition problem is a variant in which, instead of a set ''S'' with 3 integers, there are three sets ''A'', ''B'', ''C'' with ''m'' integers in each. The sum of numbers in all sets is . The goal is to construct ''m'' triplets, each of which contains one element from A, one from B and one from C, such that the sum of each triplet is ''T''. This problem can be reduced to 3-partition as follows. Construct a set S containing the numbers for each ; for each ; and for each . Every solution of the ABC-partition instance induces a solution of the 3-partition instance with sum
. Conversely, in every solution of the 3-partition instance, all triplet-sums must have the same hundreds, tens and units digits, which means that they must have exactly 1 in each of these digits. Therefore, each triplet must have exactly one number of the form , one and one . Hence, it induces a solution to the ABC-partition instance.
* The ABC-partition problem is also called
numerical 3-d matching, as it can also be reduced to the
3-dimensional matching
In the mathematical discipline of graph theory, a 3-dimensional matching is a generalization of bipartite matching (also known as 2-dimensional matching) to 3-partite hypergraphs, which consist of hyperedges each of which contains 3 vertices (i ...
problem: given an instance of ABC-partition, construct a tripartite hypergraph with sides , where there is an hyperedge for every three vertices in such that
. A matching in this hypergraph corresponds to a solution to ABC-partition.
Proofs
Garey and Johnson (1975) originally proved 3-Partition to be NP-complete, by a reduction from
3-dimensional matching
In the mathematical discipline of graph theory, a 3-dimensional matching is a generalization of bipartite matching (also known as 2-dimensional matching) to 3-partite hypergraphs, which consist of hyperedges each of which contains 3 vertices (i ...
. The classic reference by Garey and Johnson (1979) describes an NP-completeness proof, reducing from 3-dimensional matching to 4-partition to 3-partition.
Applications
The NP-hardness of 3-partition was used to prove the NP-hardness
rectangle packing, as well as of
Tetris
''Tetris'' (russian: link=no, Тетрис) is a puzzle video game created by Soviet Union, Soviet software engineer Alexey Pajitnov in 1984. It has been published by several companies for multiple platforms, most prominently during a dispute o ...
and some other puzzles, and some
job scheduling problems.
References
{{Reflist
Strongly NP-complete problems
Number partitioning