The **3-partition problem** is a strongly NP-complete problem in computer science. The problem is to decide whether a given multiset of integers can be partitioned into triplets that all have the same sum. More precisely:

- Input: a multiset
*S*containing*n*positive integer elements. - Conditions:
*S*must be partitionable into*m*triplets,*S*_{1},*S*_{2}, …,*S*_{m}, where*n = 3m*. These triplets partition*S*in the sense that they are disjoint and they cover*S*. The target value*T*is computed by taking the sum of all elements in*S*, then divided by*m*. - Output: whether or not there exists a partition of
*S*such that, for all triplets, the sum of the elements in each triplet equals*T*.

The 3-partition problem remains strongly NP-complete under the restriction that every integer in *S* is strictly between *T*/4 and *T*/2.

- 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.

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.

The 3-partition problem is similar to the partition problem, in which the goal is to partition *S* into two subsets with equal sum, and the multiway number partitioning, 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 algorithm.

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

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.^{[1]}

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 _{r}* of the restricted variant, with 3

The **ABC-partition problem** (also called **numerical 3-d matching)** is a variant in which, instead of a set *S* with 3 *m* 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*.^{[2]}

The **4-partition problem** is a variant in which *S* contains *n* = 4 *m* 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-parititon** is a variant of 4-partition in which each there are 4 input sets and each quadruplet should contain one element from each set.

Garey and Johnson (1975) originally proved 3-Partition to be NP-complete, by a reduction from 3-dimensional matching.^{[3]} The classic reference by Garey and Johnson (1979) describes an NP-completeness proof, reducing from 3-dimensional matching to 4-partition to 3-partition.^{[4]} Logically, the reduction can be partitioned into several steps.

We are given an instance of E of 3d-matching, containing some *m* triplets {w_{i},x_{j},y_{k}}, where the vertices are w_{1},...,w_{q} and x_{1},...,x_{q} and y_{1},...,y_{q}. We construct an instance of ABCD-partition with 4**m* elements, as follows (where r := 32q):

- For each triplet t = {w
_{i},x_{j},y_{k}} in E, the set A contains an element u_{t}= 10r^{4}-kr^{3}-jr^{2}-ir. - For each triplet t = {w
_{i},x_{j},y_{k}} in E, the set B contains w_{it}, C contains x_{jt}, and D contains y_{kt}. So for each of w_{i}, x_{j}, y_{k}, 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:- w
_{i}[1] = 10r^{4}+ir; w_{i}[2..] = 11r^{4}+ir. - x
_{j}[1] = 10r^{4}+jr^{2}; x_{j}[2..] = 11r^{4}+jr^{2}. - y
_{k}[1] = 10r^{4}+kr^{3}; y_{k}[2..] = 8r^{4}+kr^{3}.

- w
- The sum of every three "real" elements or every three "dummy" elements is 30r
^{4}+ir+jr^{2}+kr^{3}; and if the triplet element is added, the sum is 40r^{4}. - The threshold for the ABCD-partition instance is T=40r
^{4}. 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=*{*w*} in the matching, we construct a 4-set {u_{i},x_{j},y_{k}_{t}, w_{i}[1], x_{j}[1], y_{k}[1]}. - 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 40r^{4} as needed.

Given a partition of ABCD, the sum of each 4-set is 40r^{4}. Therefore, the terms with r, r^{2} and r^{3} must cancel out, and the terms with r^{4} must sum up to 40r^{4}; 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.

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.

We are given an instance *A* of 4-partition: 4*m* integers, a_{1},...,a_{4m}, 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
*a*in A, B contains a "regular" element_{i}*w*= 4*(5T+a_{i}_{i})+1. All in all there are 4*m*regular elements, summing up to 81mT + 4m. - For each pair of elements a
_{i},a_{j}in A, B contains two "pairing" elements: u_{ij}= 4*(6T - a_{i}- a_{j})+2 and u_{ij}' = 4*(5T + a_{i}+ a_{j})+2. All in all there are 4*m**(4*m*-1) pairing elements, summing up to (88mT+16m)*(4*m*-1). - Additionally, B contains 8m
^{2}-3m "filler" elements, with size 20T, and total sum (8m^{2}-3m)*20T. - All in all, B contains 24m
^{2}-3m = 3(8m^{2}-m) elements, with sum (64T+4)*(8m^{2}-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 {a
_{1},a_{2},a_{3},a_{4}} with sum T, we construct a 3-set {w_{1},w_{2},u_{12}} with sum 4*(5T+a_{1}+5T+a_{2}+6T-a_{1}-a_{2})+1+1+2=64T+4 and another 3-set {w_{3},w_{4},u_{12}'} with sum 4*(5T+a_{3}+5T+a_{4}+5T+a_{1}+a_{2})+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 {u
_{ij},u_{ij}',filler} with sum 4*(6T-a_{i}-a_{j}+5T+a_{i}+a_{j}+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 u
_{ij}, u_{kl}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 (a_{i}+a_{j}=a_{k}+a_{l}). Therefore, by replacing as needed, we can assume that the two pairing items are in fact u_{ij}and u_{ij}'. 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 u_{ij}, and*n*3-sets containing the items u_{ij}'. In each matching pair of 3-sets, the sum of the two pairing items u_{ij}+u_{ij}' 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.

The NP-hardness of 3-partition was used to prove the NP-hardness rectangle packing, as well as of Tetris^{[5]}^{[6]} and some other puzzles,^{[7]} and some job scheduling problems.^{[8]}

**^**Hulett, Heather; Will, Todd G.; Woeginger, Gerhard J. (2008-09-01). "Multigraph realizations of degree sequences: Maximization is easy, minimization is hard".*Operations Research Letters*.**36**(5): 594–596. doi:10.1016/j.orl.2008.05.004. ISSN 0167-6377.**^**Demaine, Erik (2015). "MIT OpenCourseWare - Hardness made Easy 2 - 3-Partition I".*Youtube*. Archived from the original on 2021-12-14.**^**Garey, Michael R. and David S. Johnson (1975). "Complexity results for multiprocessor scheduling under resource constraints".*SIAM Journal on Computing*.**4**(4): 397–411. doi:10.1137/0204035.**^**Garey, Michael R. and David S. Johnson (1979),*Computers and Intractability; A Guide to the Theory of NP-Completeness*. ISBN 0-7167-1045-5. Pages 96–105 and 224.**^**"Tetris is hard, even to approximate".*Nature*. 2002-10-28. doi:10.1038/news021021-9. ISSN 0028-0836.**^**BREUKELAAR, RON; DEMAINE, ERIK D.; HOHENBERGER, SUSAN; HOOGEBOOM, HENDRIK JAN; KOSTERS, WALTER A.; LIBEN-NOWELL, DAVID (2004-04-01). "Tetris is Hard, Even to Approximate".*International Journal of Computational Geometry & Applications*.**14**(1n02): 41–68. arXiv:cs/0210020. doi:10.1142/s0218195904001354. ISSN 0218-1959. S2CID 1177.**^**Demaine, Erik D.; Demaine, Martin L. (2007-06-01). "Jigsaw Puzzles, Edge Matching, and Polyomino Packing: Connections and Complexity".*Graphs and Combinatorics*.**23**(S1): 195–208. doi:10.1007/s00373-007-0713-4. ISSN 0911-0119. S2CID 17190810.**^**Bernstein, D.; Rodeh, M.; Gertner, I. (1989). "On the complexity of scheduling problems for parallel/pipelined machines".*IEEE Transactions on Computers*.**38**(9): 1308–1313. doi:10.1109/12.29469. ISSN 0018-9340.