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 or3-Partition vs Partition
The 3-partition problem is similar to theVariants
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 ''Su'' of the unrestricted variant, construct a new instance of the restricted version . Every solution of ''Su'' corresponds to a solution of ''Sr'' but with a sum of 7 instead of ''T'', and every element of ''Sr'' 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 ''Sr'' of the restricted variant, with 3''m'' items summing up to ''mT'', construct a new instance of the unrestricted variant , with 3m items summing up to 7mT, and with target sum 7. Every solution of ''Sr'' naturally corresponds to a solution of ''Su''. Conversely, in every solution of ''Su'', 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 ''Sr''. The ABC-partition problem (also called numerical 3-d matching) 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''. 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'' quadruplets, all with a sum of ''T''. It can be assumed that each integer is strictly between ''T''/5 and ''T''/3. Similarly, ABCD-partition is a variant of 4-partition in which there are 4 input sets and each quadruplet should contain one element from each set.Proofs
Garey and Johnson (1975) originally proved 3-Partition to be NP-complete, by a reduction from 3-dimensional matching. The classic reference by Garey and Johnson (1979) describes an NP-completeness proof, reducing from 3-dimensional matching to 4-partition to 3-partition. Logically, the reduction can be partitioned into several steps.Reduction from 3d-matching to ABCD-partition
We are given an instance of E of 3d-matching, containing some ''m'' triplets , where the vertices are w1,...,wq and x1,...,xq and y1,...,yq. We construct an instance of ABCD-partition with 4*''m'' elements, as follows (where r := 32q): * For each triplet t = in E, the set A contains an element ut = 10r4-kr3-jr2-ir. * For each triplet t = in E, the set B contains wit, C contains xjt, and D contains ykt. So for each of wi, xj, yk, there may be many corresponding elements in B, C, D - one for each triplet in which they appear. We consider one of these elements (denoted by "1") as the "real" one, and the others as "dummy" ones. The element sizes are as follows: ** wi = 10r4+ir; wi ..= 11r4+ir. ** xj = 10r4+jr2; xj ..= 11r4+jr2. ** yk = 10r4+kr3; yk ..= 8r4+kr3. * The sum of every three "real" elements or every three "dummy" elements is 30r4+ir+jr2+kr3; and if the triplet element is added, the sum is 40r4. * The threshold for the ABCD-partition instance is T=40r4. Note that the size of each element is in (T/3,T/5). Given a perfect matching in ''E'', we construct a 4-partition of ABCD as follows: * For each triplet ''t='' in the matching, we construct a 4-set . * For each triplet not in the matching, we construct a similar 4-set, but with the corresponding dummy elements. In both cases, the sum of the 4-set is 40r4 as needed. Given a partition of ABCD, the sum of each 4-set is 40r4. Therefore, the terms with r, r2 and r3 must cancel out, and the terms with r4 must sum up to 40r4; so the 4-set must contain a triplet and 3 matching "real" elements, or a triplet and 3 matching "dummy" elements. From the triplets with the 3 matching "real" elements, we construct a valid perfect matching in E. Note that, in the above reduction, the size of each element is polynomial in the input size; hence, this reduction shows that ABCD-partition is ''strongly'' NP-hard.Reduction from ABCD-partition to 4-partition
Given an instance of ABCD-partition with ''m'' elements per set, threshold ''T'', and sum ''mT'', we construct an instance of 4-partition with 4''m'' elements: * For each element a in A, the corresponding element has size 16a+1; * For each element b in B, the corresponding element has size 16b+2; * For each element c in C, the corresponding element has size 16c+4; * For each element d in D, the corresponding element has size 16d+8. All in all, the sum is 16mT+15m, and the new threshold is 16T+15. Every ABCD-partition corresponds naturally to a 4-partition. Conversely, in every 4-partition, the sum modulo 16 is 15, and therefore it must contain exactly one item with size modulo 16 = 1, 2, 4, 8; this corresponds to exactly one item from A, B, C, D, from which we can construct an ABCD-partition. Using a similar reduction, ABC-partition can be reduced to 3-partition.Reduction from 4-partition to 3-partition
We are given an instance ''A'' of 4-partition: 4''m'' integers, a1,...,a4m, each of which in the range (T/3,T/5), summing up to ''mT''. We construct an instance ''B'' of 3-partition as follows: * For each ''ai'' in A, B contains a "regular" element ''wi'' = 4*(5T+ai)+1. All in all there are 4''m'' regular elements, summing up to 81mT + 4m. * For each pair of elements ai,aj in A, B contains two "pairing" elements: uij = 4*(6T - ai - aj)+2 and uij' = 4*(5T + ai + aj)+2. All in all there are 4''m*''(4''m''-1) pairing elements, summing up to (88mT+16m)*(4''m''-1). * Additionally, B contains 8m2-3m "filler" elements, with size 20T, and total sum (8m2-3m)*20T. * All in all, B contains 24m2-3m = 3(8m2-m) elements, with sum (64T+4)*(8m2-m). * The threshold for the 3-partition instance is 64T+4; note that the sizes of all elements in B are in (16T+1,32T+2). Given a 4-partition of ''A'', we construct a 3-partition for B as follows: * For each 4-set with sum T, we construct a 3-set with sum 4*(5T+a1+5T+a2+6T-a1-a2)+1+1+2=64T+4 and another 3-set with sum 4*(5T+a3+5T+a4+5T+a1+a2)+1+1+2=64T+4. These sets contain all 4m regular elements and 2m matching pairs of pairing elements. * From the remaining elements, we construct 3-sets with sum 4*(6T-ai-aj+5T+ai+aj+5T)+2+2=64T+4. Conversely, given a 3-partition of B, the sum of each 3-set is a multiple of 4, so it must contain either two regular items and one pairing item, or two pairing items and one filler item: * If a 3-set contains two pairing items uij, ukl and one filler item, then the sum of the two pairing items must be 44T+4 = 4*(5T+6T)+2+2, so they must have matching sizes (ai+aj=ak+al). Therefore, by replacing as needed, we can assume that the two pairing items are in fact uij and uij'. Therefore, the remaining pairing items also consist of ''n'' matching pairs. * Therefore, the remaining 3-sets can be partitioned into two groups: ''n'' 3-sets containing the items uij, and ''n'' 3-sets containing the items uij'. In each matching pair of 3-sets, the sum of the two pairing items uij+uij' is 44T+4, so the sum of the four regular items is 84T+4. Therefore, from the four regular items, we construct a 4-set in A, with sum T.Applications
The NP-hardness of 3-partition was used to prove the NP-hardness rectangle packing, as well as ofReferences
{{Reflist Strongly NP-complete problems Number partitioning