3-partition problem: Difference between revisions

Content deleted Content added
Variants: added a factor 7 that was missing
 
(44 intermediate revisions by 19 users not shown)
Line 1:
{{Short description|Strongly NP-complete problem in computer science}}
The '''3-partition problem''' is a [[Strong NP-completeness|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:
 
* The input to the problem isInput: a multiset ''S'' ofcontaining ''n'' = 3 ''m'' positive integers.integer The sum of all integers is ''m T''elements.
* The output is whether or not there exists a partition ofConditions: ''S'' must be partitionable into ''m'' triplets, ''S''<sub>1</sub>, ''S''<sub>2</sub>, ..., ''S''<sub>''m''</sub>, such that the sum of the numbers in each one is equal towhere ''T''.n The= 3m''S''<sub>1</sub>,. ''S''<sub>2</sub>, …,These ''S''<sub>''m''</sub> must form atriplets [[Partition of a set|partition]] of ''S'' in the sense that they are [[Disjoint sets|disjoint]] and they [[Cover (topology)|cover]] ''S''. The target value ''T'' is computed by taking the sum of all elements in ''S'', then dividing 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.
Line 8 ⟶ 10:
==Example==
 
# The set ''<math>S'' = \{ 20, 23, 25, 30, 49, 45, 27, 30, 30, 40, 22, 19 \}</math> can be partitioned into the threefour sets <math>\{ 20, 25, 45 \}, \{ 23, 27, 40 \}, \{ 49, 22, 19 \} , \{ 30, 30, 30\}</math>, each of which sumsums to ''T'' = 90.
# The set <math>S = \{1, 2, 5, 6, 7, 9\}</math> can be partitioned into the two sets <math>\{1, 5, 9\}, \{2, 6, 7\}</math> each of which sum to ''T'' = 15.
# (every integer in ''S'' is strictly between ''T''/4 and ''T''/2): <math>S = \{4,5,5,5,5,6\}</math>, thus ''m''=2, and ''T''=15. There is feasible 3-partition <math>\{4,5,6\}, \{5,5,5\}</math>.
# (every integer in ''S'' is strictly between ''T''/4 and ''T''/2): <math>S = \{4,4,4,6,6,6\}</math>, thus ''m''=2, and ''T''=15. There is no feasible solution.
 
==Strong NP-completeness==
Line 15 ⟶ 20:
 
== 3-Partition vs Partition ==
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'' subsets (or= ''n''/3 subsets), not just twoa fixed number of subsets, with equal sum. Partition is "easier" than 3-Partition: while 3-Partition is [[strongly NP-hard]], Partition is only [[Weak NP-completeness|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 athe [[Pseudo-polynomialpseudopolynomial time|pseudopolynomial timenumber partitioning]] 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<sub>u</sub>'' of the unrestricted variant, construct a new instance of the restricted version {{math|''S<sub>r</sub>'' := {s + 2 {{hsp|''T''}} |{{!}} s in&isin; ''S<sub>u</sub>''}}}. Every solution of ''S<sub>u</sub>'' corresponds to a solution of ''S<sub>r</sub>'' but with a sum of 7 {{hsp|''T''}} instead of ''T'', and every element of ''S<sub>r</sub>'' is in {{nowrap|[2 {{hsp|''T''}}, 3 {{hsp|''T''}}]}} which is contained in ({{nowrap|{{pars|7 {{hsp|''T'' }}/ 4, 7 {{hsp|''T'' }}/ 2)}}}}.
 
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.<ref>{{Cite journal|lastlast1=Hulett|firstfirst1=Heather|last2=Will|first2=Todd G.|last3=Woeginger|first3=Gerhard J.|date=2008-09-01|title=Multigraph realizations of degree sequences: Maximization is easy, minimization is hard|url=http://www.sciencedirect.com/science/article/pii/S0167637708000552|journal=Operations Research Letters|language=en|volume=36|issue=5|pages=594–596|doi=10.1016/j.orl.2008.05.004|issn=0167-6377|url-access=subscription}}</ref>
 
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<sub>ur</sub>'' of the restricted variant, with 3''m'' items summing up to ''mT'', construct a new instance of the unrestricted variant {{math|''S<sub>ru</sub>'' := {s + 2 ''T'' |{{!}} s in&isin; ''S<sub>ur</sub>''}}}, with 3m items summing up to 7mT, and with target sum 7 {{hsp|''T''}}. Every solution of ''S<sub>ur</sub>'' naturally corresponds to a solution of ''S<sub>ru</sub>''. InConversely, in every solution of ''S<sub>ru</sub>'', since the target sum is 7 {{hsp|''T''}} and each element is in ({{nowrap|{{pars|7 {{hsp|''T'' }}/ 4, 7 {{hsp|''T'' }}/ 2)}}}}, there must be exactly 3 elements per set, so it corresponds to a solution of ''S<sub>ur</sub>''.
 
The '''ABC-partition problem''' (also called '''[[Numerical 3-dimensional matching|numerical 3-d matching]])''' is a variant in which, instead of a set ''S'' with 3{{hsp|''m''}} integers, there are three sets ''A'', ''B'', ''C'' with ''m'' integers in each. The sum of numbers in all sets is {{tmath|m T}}. 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''.<ref>{{Cite web|last=Demaine|first=Erik|date=2015|title=MIT OpenCourseWare - Hardness made Easy 2 - 3-Partition I|url=https://www.youtube.com/watch?v=ZaSMm2xvatw |archive-url=https://ghostarchive.org/varchive/youtube/20211214/ZaSMm2xvatw |archive-date=2021-12-14 |url-status=live|website=Youtube}}{{cbignore}}</ref>
The '''4-partition problem''' is a variant in which ''S'' contains ''n'' = 4 ''m'' integers, the sum of all integers is ''m T'', 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 '''4-partition problem''' is a variant in which ''S'' contains ''n'' = 4 {{hsp|''m''}} integers, the sum of all integers is ''{{tmath|m T''}}, and the goal is to partition it into ''m'' quadruplesquadruplets, 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.
The '''ABC-partition problem''' 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 ''m T''. 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''. <ref>{{Cite web|last=Demaine|first=Erik|date=2015|title=MIT OpenCourseWare - Hardness made Easy 2 - 3-Partition I|url=https://www.youtube.com/watch?v=ZaSMm2xvatw|url-status=live|archive-url=|archive-date=|access-date=|website=Youtube}}</ref> This problem can be reduced to 3-partition as follows. Construct a set S containing the numbers 1000''a''+100 for each ''a'' in A; 1000''b''+10 for each ''b'' in B; and 1000''c''+1 for each ''c'' in C. Every solution of the ABC-partition instance induces a solution of the 3-partition instance with sum 1000''(a+b+c)''+111 = 1000''T''+111. Conversely, in every solution of the 3-partition instance, all triplet-sums must have the same hunderds, 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 1000''a''+100, one 1000''b''+10 and one 1000''c''+1. Hence, it induces a solution to the ABC-partition instance.
 
* The ABC-partition problem is also called '''numeric 3-d matching''', as it can also be reduced to the [[3-dimensional matching]] problem: given an instance of ABC-partition, construct a tripartite hypergraph with sides A, B, C, where there is an hyperedge (a, b, c) for every three vertices in A, B, C such that a+b+c = ''T''. 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]].<ref>{{cite journal|author=[[Michael Garey|Garey, Michael R.]] and [[David S. Johnson]]|year=1975|title=Complexity (1979),results ''Computersfor andmultiprocessor Intractability;scheduling Aunder Guideresource toconstraints|journal=SIAM theJournal Theoryon of NP-Completeness''Computing|volume=4|issue=4|pages=397–411|doi=10. {{ISBN|0-7167-1045-51137/0204035}}. Pages 96–105 and 224.</ref> The classic reference by Garey and Johnson (1979) describes an NP-completeness proof, reducing from 3-dimensional matching to 4-partition to 3-partition.<ref>{{cite journal|author=[[Michael Garey|Garey, Michael R.]] and [[David S. Johnson]]|year=1975|title=Complexity results(1979), for''Computers multiprocessorand schedulingIntractability; underA resourceGuide constraints|journal=SIAMto Journalthe onTheory Computing|volume=4|issue=4|pages=397–411|doi=10of NP-Completeness''.1137/0204035 {{ISBN|0-7167-1045-5}}. Pages 96–105 and 224.</ref> 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 {w<sub>i</sub>,x<sub>j</sub>,y<sub>k</sub>}, where the vertices are w<sub>1</sub>,...,w<sub>q</sub> and x<sub>1</sub>,...,x<sub>q</sub> and y<sub>1</sub>,...,y<sub>q</sub>. We construct an instance of ABCD-partition with 4*''m'' elements, as follows (where r := 32q):
* For each triplet t = {w<sub>i</sub>,x<sub>j</sub>,y<sub>k</sub>} in E, the set A contains an element u<sub>t</sub> = 10r<sup>4</sup>-kr<sup>3</sup>-jr<sup>2</sup>-ir.
* For each triplet t = {w<sub>i</sub>,x<sub>j</sub>,y<sub>k</sub>} in E, the set B contains w<sub>it</sub>, C contains x<sub>jt</sub>, and D contains y<sub>kt</sub>. So for each of w<sub>i</sub>, x<sub>j</sub>, y<sub>k</sub>, 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<sub>i</sub>[1] = 10r<sup>4</sup>+ir; w<sub>i</sub>[2..] = 11r<sup>4</sup>+ir.
** x<sub>j</sub>[1] = 10r<sup>4</sup>+jr<sup>2</sup>; x<sub>j</sub>[2..] = 11r<sup>4</sup>+jr<sup>2</sup>.
** y<sub>k</sub>[1] = 10r<sup>4</sup>+kr<sup>3</sup>; y<sub>k</sub>[2..] = 8r<sup>4</sup>+kr<sup>3</sup>.
* The sum of every three "real" elements or every three "dummy" elements is 30r<sup>4</sup>+ir+jr<sup>2</sup>+kr<sup>3</sup>; and if the triplet element is added, the sum is 40r<sup>4</sup>.
* The threshold for the ABCD-partition instance is T=40r<sup>4</sup>. 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<sub>i</sub>,x<sub>j</sub>,y<sub>k</sub>''} in the matching, we construct a 4-set {u<sub>t</sub>, w<sub>i</sub>[1], x<sub>j</sub>[1], y<sub>k</sub>[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<sup>4</sup> as needed.
 
Given a partition of ABCD, the sum of each 4-set is 40r<sup>4</sup>. Therefore, the terms with r, r<sup>2</sup> and r<sup>3</sup> must cancel out, and the terms with r<sup>4</sup> must sum up to 40r<sup>4</sup>; 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, a<sub>1</sub>,...,a<sub>4m</sub>, 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<sub>i</sub>'' in A, B contains a "regular" element ''w<sub>i</sub>'' = 4*(5T+a<sub>i</sub>)+1. All in all there are 4''m'' regular elements, summing up to 81mT + 4m.
* For each pair of elements a<sub>i</sub>,a<sub>j</sub> in A, B contains two "pairing" elements: u<sub>ij</sub> = 4*(6T - a<sub>i</sub> - a<sub>j</sub>)+2 and u<sub>ij</sub>' = 4*(5T + a<sub>i</sub> + a<sub>j</sub>)+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<sup>2</sup>-3m "filler" elements, with size 20T, and total sum (8m<sup>2</sup>-3m)*20T.
* All in all, B contains 24m<sup>2</sup>-3m = 3(8m<sup>2</sup>-m) elements, with sum (64T+4)*(8m<sup>2</sup>-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<sub>1</sub>,a<sub>2</sub>,a<sub>3</sub>,a<sub>4</sub>} with sum T, we construct a 3-set {w<sub>1</sub>,w<sub>2</sub>,u<sub>12</sub>} with sum 4*(5T+a<sub>1</sub>+5T+a<sub>2</sub>+6T-a<sub>1</sub>-a<sub>2</sub>)+1+1+2=64T+4 and another 3-set {w<sub>3</sub>,w<sub>4</sub>,u<sub>12</sub>'} with sum 4*(5T+a<sub>3</sub>+5T+a<sub>4</sub>+5T+a<sub>1</sub>+a<sub>2</sub>)+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<sub>ij</sub>,u<sub>ij</sub>',filler} with sum 4*(6T-a<sub>i</sub>-a<sub>j</sub>+5T+a<sub>i</sub>+a<sub>j</sub>+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<sub>ij</sub>, u<sub>kl</sub> 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<sub>i</sub>+a<sub>j</sub>=a<sub>k</sub>+a<sub>l</sub>). Therefore, by replacing as needed, we can assume that the two pairing items are in fact u<sub>ij</sub> and u<sub>ij</sub>'. 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<sub>ij</sub>, and ''n'' 3-sets containing the items u<sub>ij</sub>'. In each matching pair of 3-sets, the sum of the two pairing items u<sub>ij</sub>+u<sub>ij</sub>' 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 of [[Tetris#Computational complexity|Tetris]]<ref>{{Cite journal|date=2002-10-28|title=Tetris is hard, even to approximate|url=http://dx.doi.org/10.1038/news021021-9|journal=Nature|doi=10.1038/news021021-9|issn=0028-0836|url-access=subscription}}</ref><ref>{{Cite journal|lastlast1=BREUKELAAR|firstfirst1=RON|last2=DEMAINE|first2=ERIK D.|last3=HOHENBERGER|first3=SUSAN|last4=HOOGEBOOM|first4=HENDRIK JAN|last5=KOSTERS|first5=WALTER A.|last6=LIBEN-NOWELL|first6=DAVID|date=2004-04-01|title=TETRISTetris ISis HARDHard, EVENEven TOto APPROXIMATEApproximate|date=2004-04-01|url=http://dx.doi.org/10.1142/s0218195904001354|journal=International Journal of Computational Geometry & Applications|volume=14|issue=01n021n02|pages=41–68|doi=10.1142/s0218195904001354|issn=0218-1959|viaarxiv=cs/0210020|s2cid=1177 }}</ref> and some other puzzles,<ref>{{Cite journal|lastlast1=Demaine|firstfirst1=Erik D.|last2=Demaine|first2=Martin L.|date=2007-06-01|title=Jigsaw Puzzles, Edge Matching, and Polyomino Packing: Connections and Complexity|url=http://dx.doi.org/10.1007/s00373-007-0713-4|journal=Graphs and Combinatorics|volume=23|issue=S1|pages=195–208|doi=10.1007/s00373-007-0713-4|s2cid=17190810 |issn=0911-0119|viaurl-access=subscription}}</ref> and some [[Job scheduling|job scheduling problemproblems]]<nowiki/>s.<ref>{{Cite journal|lastlast1=Bernstein|firstfirst1=D.|last2=Rodeh|first2=M.|last3=Gertner|first3=I.|date=1989|title=On the complexity of scheduling problems for parallel/pipelined machines|url=http://dx.doi.org/10.1109/12.29469|journal=IEEE Transactions on Computers|volume=38|issue=9|pages=1308–1313|doi=10.1109/12.29469|issn=0018-9340|url-access=subscription}}</ref>
 
==References==
{{Reflist}}
[[Category:Strongly NP-complete problems]]
[[Category:Number partitioning]]