Equal sum subsets: Complexity of variations

12

Transcript of Equal sum subsets: Complexity of variations

Equal Sum Subsets: Complexity of VariationsMark Cieliebak�, Stephan Eidenbenz�, Aris Pagourtzis�, and Konrad Schlude�AbstractWe start an investigation into the complexity of variations of the Equal Sum Subsetsproblem, a basic problem in which we are given a set of numbers and are asked to �nd twodisjoint subsets of the numbers that add up to the same sum. While Equal Sum Subsetsis known to be NP -complete, only very few studies have investigated the complexity of itsvariations. In this paper, we show NP -completeness for two very natural variations, namelyFactor-r Sum Subsets, where we need to �nd two subsets such that the ratio of theirsums is exactly r, and k Equal Sum Subsets, where we need to �nd k subsets of equalsum. In an e�ort to gain an intuitive understanding of what makes a variation of EqualSum Subsets NP -hard, we study several variations of Equal Sum Subsets in which weintroduce additional requirements that a solution must ful�ll (e.g., the cardinalities of thetwo sets must di�er by exactly one), and prove NP -hardness for these variations. Finally, weinvestigate and show NP -hardness for the Equal Sum Subsets from Two Sets problemand its variations, where we are given two sets and we need to �nd two subsets of equal sum.Our results leave us with a family of NP -complete problems that gives insight on the sphereof NP -completeness around Equal Sum Subsets.1 IntroductionThe problem Partition, which asks whether there exists a subset A0 of a given set A of numberssuch that the elements of A0 add up to exactly one half of the total sum of all numbers of A, isone of the basic combinatorial problems and has long been known to be NP -complete [4]. Weare interested in a variation of Partition which we call Equal Sum Subsets. Equal SumSubsets simply asks for two disjoint subsets of a given set of numbers that add up to the sametotal. In order to give a formal de�nition of Equal Sum Subsets, we denote the sum of theelements of a set X of integers by sum(X), i.e. sum(X) :=Px2X x.De�nition (Equal Sum Subsets). Given a set1 of n numbers A = fa1; : : : ; ang, are theretwo disjoint nonempty subsets X; Y � A such that sum(X) = sum(Y )?Equal Sum Subsets is a very natural problem that is known to be NP -complete [9]. Therealso exists an FPTAS for an optimization version of Equal Sum Subsets, in which the ratioof the sums of the two disjoint subsets is to be minimized [1]. Moreover, the problem has beenstudied in a restricted version, in which the sum of the n elements is at most 2n � 1, in thecontext of function problems [6].�Institute of Theoretical Computer Science, ETH Z�urich, fcielieba, eidenben, pagour, [email protected] do not allow multi-sets here as the problem is trivially solvable if the same number exists more than oncein the input. 1

While Partition, Equal Sum Subsets and variations have numerous applications in pro-duction planning and scheduling (see [5] for a survey), our interest for Equal Sum Subsetscomes from computational biology. We brie y illustrate this connection (more details can befound in [2]). In the PartialDigest problem we are given a multiset D of distances and areasked to �nd coordinates of points on a line such that D is exactly the multiset of all pair-wisedistances of these points. PartialDigest is a basic problem from DNA sequencing. Neithera polynomial-time algorithm nor a proof of NP -completeness is known for this problem. Wehave de�ned an optimization variation of PartialDigest and proved its NP -hardness using areduction from Equal Sum Subsets.In this paper, we study the computational complexity of a number of variations of EqualSum Subsets. After �xing some notation for large numbers that we will use in some of ourproofs (Section 2), we study a �rst set of Equal Sum Subsets variations that we call Factor-r Sum Subsets (for any rational r > 0): Given a set of numbers A = fa1; : : : ; ang, are theredisjoint subsets X; Y � A such that sum(X) = r � sum(Y )? Factor-r Sum Subsets is avery natural variation of Equal Sum Subsets. In Section 3, we show that Factor-r SumSubsets is NP -complete for any factor r > 0 by giving two reductions from One-in-Three3-Satisfiability, one that works for all r > 0 except r = 1 and r = 2, and one that works forthe case r = 2 and uses an argument about the connectivity of Boolean formulas. The case forr = 1 is equivalent to Equal Sum Subsets.In Section 4, we study a second generalization of Equal Sum Subsets, namely k EqualSum Subsets, in which we need to �nd k (disjoint) subsets of equal sum from a given set ofnumbers. k Equal Sum Subsets is a variation of Equal Sum Subsets with an importanceof its own. We show that k Equal Sum Subsets is NP -complete for any integer k � 3by proposing a reduction from Alternating Partition, which is an NP -complete variationof Partition [3]. The NP -completeness for the case k = 2 follows directly from the NP -completeness of Equal Sum Subsets.In our e�ort to gain an intuitive understanding of what makes a variation NP -hard, we studyvariations of Equal Sum Subsets where we add additional requirements that the solution mustful�ll. In Section 5, we show NP -completeness for the following three variations by proposingreductions from Alternating Partition: Equal Sum Subsets with Enforced Element(where a speci�c element, say an, must belong to one of the two subsets), Equal Sum Subsetsof Different Cardinality (where the two subsets must be of di�erent cardinality), andEqual Sum Subsets of Different by One Cardinality (where the cardinalities of thetwo subsets must di�er by exactly one). We also show that Alternating Partial Partitionis NP -complete by reduction from Equal Sum Subsets. As a last result of this section,we show that Equal Sum Subsets of Equal Cardinality (i.e., the problem in which thetwo equal sum subsets must also be of equal cardinality) is NP -complete by reduction fromAlternating Partial Partition.In order to determine the realm of NP -completeness around Alternating Partial Par-tition, we study closely related problems, namely the Equal Sum Subsets from Two Setsproblem and some of its variations; in this problem, we are given two sets of positive numbersA and B and the question is if there are subsets X � A and Y � B of equal sum. In Section 6,we show that Equal Sum Subsets from Two Sets is NP -complete, even if we require thetwo sets to be of equal cardinality, or to have disjoint indices sets, or disjoint covering indicessets, or identical indices sets. 2

We conclude in Section 7 with a brief discussion and some ideas for further research.2 Number RepresentationIn many of our proofs, we use numbers which are expressed in the number system of some baseB. We denote by ha1; : : : ; aniB the number P1�i�n aiBn�i ; we say that ai is the i-th digitof this number. Usually, we choose base B large enough such that adding up numbers willnot lead to carry-digits from one digit to the next. Therefore, we can add numbers digit bydigit. The same holds for scalar products. For example, having base B = 27 and numbers� = h3; 5; 1i; � = h2; 1; 0i, then �+ � = h5; 6; 1i and 3 � � = h9; 15; 3i.We will generally make liberal use of the notation such as allowing di�erent bases for eachdigit or dropping the base B from our notation if this is clear from the context. We de�nethe concatenation of two numbers by ha1; : : : ; ani � hb1; : : : ; bmi := ha1; : : : ; an; b1; : : : ; bmi, i.e.�� � = �Bm+�, wherem is the number of digits in �. We will use �n(i) := h0; : : : ; 0; 1; 0; : : : ; 0ifor the number that has n digits, all 0's except for the i-th position where the digit is 1. Fur-thermore, 1n := h1; : : : ; 1i is the number that has n digits, all 1's, and 0n := h0; : : :0i has nzeros. Notice that 1n = Bn � 1.3 NP-completeness of Factor-r Sum SubsetsIn this section, we study a natural generalization of Equal Sum Subsets that is importantper se, namely the Factor-r Sum Subsets problem, where we want to �nd two subsets whosesums have a speci�c ratio r. This is closely related to the minimization version of Equal SumSubsets studied in [1].De�nition (Factor-r Sum Subsets). Given a set of n numbers A = fa1; : : : ; ang, are theretwo disjoint nonempty subsets X; Y � A such that sum(X) = r � sum(Y )?For r = 1 the problem is Equal Sum Subsets and therefore NP -complete [9]. We showthat Factor-r Sum Subsets is actually NP -complete for all r 2 Q+. The proof consists oftwo di�erent reductions from One-in-Three 3-Satisfiability, where the second reduction isjust for the case r = 2 and involves an argument about the connectivity graph of a Booleanformula. One-in-Three 3-Satisfiability is NP -complete [3] and de�ned as follows: Given aCNF Boolean formula consisting of clauses with three positive literals each, is there a (satisfying)assignment that satis�es exactly one literal per clause?Lemma 1. One-in-Three 3-Satisfiability �p Factor-r Sum Subsets for any r 2 Q+; r 62f1; 2; 12g.Proof. Let r = p=q, where p; q are positive integers with no common divisor except 1 (coprimes)and p < q (the case p > q is equivalent by interchanging setsX and Y in problem de�nition). Wedistinguish several cases, depending on the values of p and q. We only give a detailed proof forthe �rst case; for the other cases the proof is quite similar, so we just mention the constructionof the necessary numbers. 3

Case 1: p > 3. Consider an instance of One-in-Three 3-Satisfiability with a set of nvariables V = fv1; : : : ; vng and a set of m clauses C = fc1; : : : ; cmg. An instance of Factor-rSum Subsets is constructed as follows. For each variable vi, a number ai = Pvi2cj �m(j) iscreated (i.e. ai hasm digits and its non-zero digits correspond to clauses where xi appears). Twoadditional numbers an+1 and an+2 are constructed which are multiples of 1m: an+1 = (p�1) �1mand an+2 = q � 1m. For all numbers we assume base B = q(p + q + 2) + 1 (this way we avoidcarry-digits when adding ai's). Let A = fa1; : : : ; an+2g. We show below that there is an 1-in-3satisfying assignment for the variables in V satisfying exactly one literal in each clause in C ifand only if there are two disjoint nonempty subsets X; Y � A such that sum(X) = r � sum(Y ).\only if": The existence of an 1-in-3 satisfying assignment implies that there exists a subsetR � fa1; : : : ; ang such that sum(R) = 1m: for each clause cj , there is exactly one of the threevariables in cj set to TRUE, say xk , and the corresponding ak has a one in the j-th digit. Bysetting X = R [ fan+1g and Y = fan+2g we havesum(X) = p � 1m = r � q � 1m = r � sum(Y )\if": Assume that X and Y exist such that sum(X) = r � sum(Y ); equivalently,q � sum(X) = p � sum(Y )Since the base of our numbers is su�ciently large (B = q(p+ q + 2)+ 1), we have that the sumof all numbers in A consists of m digits that are all equal to p+q+2 (sum(A) = (p+q+2) �1m)and therefore sum(X) + sum(Y ) also consists of m digits of value at most p + q + 2. Noticethat for each i � m the i-th digit of sum(X)+ sum(Y ) can be the sum of at most �ve numbers:1; 1; 1; p� 1, and q. We will argue that the only way to have sum(X)=sum(Y ) = p=q is if eachdigit of sum(X) is equal to p and each digit of sum(Y ) is equal to q.Let ZX = q � sum(X) and ZY = p � sum(Y ). We will make use of the equality ZX = ZY .Notice that, again due to the su�ciently large base B, even if we add all numbers in A q timesno carry-digits will occur; hence the same happens if we add numbers in X q times or numbersin Y p times. This means that the i-th bit of ZX is equal to qxi, where xi is the i-th bit ofsum(X), and the i-th bit of ZY is equal to pyi, where yi is the i-th bit of sum(Y ). Therefore,for all 1 � i � m we have qxi = pyi which implies that either xi = yi = 0 or q divides yi and pdivides xi; since xi + yi � p+ q + 2 and q > p > 3, we get xi = p and yi = q for some i (theremust be non-zero digits since we assumed non-empty X and Y ).It is not di�cult to see that this can only be achieved if Y = fan+2g and X = fan+1g [ R,where R � A and sum(R) = 1m. The variables corresponding to numbers in R form an 1-in-3satisfying assignment for the given clauses.Case 2: p = 3; q > 4. a1; : : : ; an as in Case 1, an+1 = 3 � 1m; an+2 = (q � 1) � 1m.Case 3: p = 3; q = 4. a1; : : : ; an as in Case 1, an+1 = 3 � 1m; an+2 = 2 � 1m.Case 4: p = 2; q > 3. a1; : : : ; an as in Case 1, and only one additional number an+1 = (q�1)�1mis constructed.Case 5: p = 2; q = 3. For each variable vi, ai = Pvi2cj 3 � �m(j), i.e. ai has a digit 3 ineach position that corresponds to a clause that contains vi. We also set an+1 = 1m. Note thatsum(A) = 10 � 1m. 4

Again, \only if" is easy: the satisfying assignment corresponds to numbers that add up to3 �1m which together with an+1 consitute X . For the \if" direction we observe that the only wayto have the required ratio is by having two sets X; Y such that sum(X) = 4�1m; sum(Y ) = 6�1m;this implies an+1 2 X and hence the variables corresponding to X�fan+1g constitute an 1-in-3satisfying assignment.Case 6: p = 1; q > 2. In this case a1; : : : ; an are constructed as in Case 1. There is only oneadditional number an+1 = q � 1m.Lemma 2. One-in-Three 3-Satisfiability �p Factor-2 Sum Subsets.Proof. We use a restricted, but still NP -hard version of One-in-Three 3-Satisfiability forour reduction to Factor-2 Sum Subsets. Given a One-in-Three 3-Satisfiability instancewith variables x1; : : : ; xn and clauses c1; : : : ; cm with only positive literals, let G = (V;E) bethe graph with vertices V = fx1; : : : ; xng (i.e., each variable corresponds to a vertex) and, fori; j = 1; : : : ; n, edges (xi; xj) 2 E if and only if xi and xj both occur in a clause ck, for somek 2 f1; : : : ; ng. The One-in-Three 3-Satisfiability variation in which the correspondinggraph G is connected is still NP -hard, because we could use a polynomial algorithm for thisvariation to solve the unrestricted One-in-Three 3-Satisfiability problem by applying thealgorithm for each component of the corresponding graph.We reduce One-in-Three 3-Satisfiability with a connected graph to Factor-2 SumSubsets as follows: Assume the satis�ability instance has n variables x1; : : : ; xn and m clausesc1; : : : ; cm. We construct an instance of Factor-2 Sum Subsets by creating exactly one numberai for each variable xi with ai =Pxi2cj �n(j); where we set the j�th digit to 1, if xi appearsas a literal in clause cj . We let the base B of these numbers be 7.Assume that we have an 1-in-3 satisfying assignment for the variables of the One-in-Three3-Satisfiability instance. We then construct a solution X; Y of the Factor-2 Sum Subsetsinstance, where Y contains all numbers ai for which the corresponding variable xi has been setto TRUE, and X contains all remaining numbers. Thus, sum(Y ) = h1; 1; : : : ; 1i and sum(X) =h2; 2; : : : ; 2i, and therefore sum(X) = 2 � sum(Y ).Now assume that we are given a solution X; Y of the Factor-2 Sum Subsets instance withsum(X) = 2 � sum(Y ). Since each digit is set to one in exactly three of the numbers ai, andsince no carry-digits can occur when summing up the ai's because base B is su�ciently large,sum(Y ) must contain only ones (and zeros) in its digits and sum(X) contains only twos (andzeros). Since the sets cannot be empty, at least one digit must be set to one. We assign thevalue TRUE to a variable xi with corresponding number ai if ai 2 Y , and we assign the valueFALSE, if ai 2 X . Thus, if a clause cj = (xf ; xg; xh) exists, then either one of the three numbersaf ; ag, or ah is in Y and the other to numbers are in X , or neither X nor Y contain af ; ag, orah. In the latter case, we know that sum(X) and sum(Y ) contain a zero at position j.However, the numbers sum(X) and sum(Y ) cannot contain any zero digits because of theconnectedness of graph G. In order to see this, assume for the sake of contradiction that sum(Y )contains zero digits. Then, sum(X) must contain zero digits at the same positions. Let digitj be such a zero and let cj = (xf ; xg; xh) be the corresponding clause. Consider the set S ofall variables that occur in clauses which represent zero digits. Then the subgraph of G withonly the vertices corresponding to variables from set S must be a component in the graph Gwithout any edges to other vertices, because, if such an edge would exist, it would imply that the5

corresponding digit is not set to zero in either sum(X) or sum(Y ). To see this, consider an edgee = (xf ; xg) arising from clause cj = (xf ; xg; xh) with xf 2 S and xg =2 S. Then ag 2 X [ Y ,but af (and ah) must be in X [ Y as well, in order to achieve the factor 2 in the j-th digit.Since Factor-r Sum Subsets is obviously inNP and since One-in-Three 3-Satisfiabilityis NP -hard, Lemmas 1 and 2 and the NP -completeness of Equal Sum Subsets imply:Theorem 3. Factor-r Sum Subsets is NP -complete for all r 2 Q+.4 NP -completeness of k Equal Sum SubsetsThe second variation of Equal Sum Subsets that we study is called k Equal Sum Subsets.For an integer k � 2 it is de�ned as follows:De�nition (k Equal Sum Subsets). Given a multi-set2 of n numbers fa1; : : : ; ang, are therek � 2 non-identical subsets X1; : : : ; Xk � fa1; : : : ; ang with sum(X1) = : : : = sum(Xk)?k Equal Sum Subsets is a very natural generalization of Equal Sum Subsets (whichis the case k = 2) and it is an interesting problem for its own sake. We present a reductionfrom Alternating Partition which is the following NP -complete [3] variation of Partition:Given n pairs of numbers (u1; v1); : : : ; (un; vn), are there two disjoint sets of indices I andJ with I [ J = f1; : : : ; ng such that Pi2I ui +Pj2J vj = Pi2I vi +Pj2J uj (equivalently,Pi2I ui +Pj2J vj =Pi62I ui +Pj 62J vj )?Theorem 4. k Equal Sum Subsets is NP -complete.Proof. The problem is obviously in NP . To show NP -hardness, we reduce Alternating Par-tition to it. We transform a givenAlternating Partition instance with pairs (u1; v1); : : : ; (un; vn)into a k Equal Sum Subsets instance as follows: For each pair (ui; vi), we create two numbersu0i = huii� �n(i) and v0i = hvii� �n(i). In addition, we create k�2 (equal) numbers c1; : : : ; ck�2with ci = h12Pi(ui + vi)i� 1(n). While we let the base of the �rst digit be k �Pi(ui + vi), allother digits have base n+ 1 in order to ensure that no carry-digits can occur in any additions.To see how this reduction works, assume �rst that we are given a solution of the Alter-nating Partition instance, i.e., two indices sets G and H . We create k equal sum subsetsS1; : : : ; Sk: for k = 1; : : : ; k�2 we have Si = fcig; for the remaining two subsets, we let u0i 2 Sk�1,if i 2 G, and v0i 2 Sk�1, if i 2 H , and we let u0i 2 Sk, if i 2 H , and v0i 2 Sk , if vi 2 G.Now assume we are given a solution of the k Equal Sum Subsets instance, i.e., k equalsum subsets S1; : : : ; Sk. Since each of the n right-most digits (i.e., the base n + 1 digits) is setto one in exactly k numbers, we can assume w.l.o.g. that Si = fcig for i = 1; : : : ; k � 2. Theremaining two subsets naturally form an alternating partition as u0i and v0i can never be in thesame subset for any i = 1; : : : ; n. All numbers u0i and v0i must occur in one of the remaining twosubsets in order to match the ones in the base n + 1 digits of the other subsets. Matching the�rst digit gives us the equal sum subsets.Note that this proof works as well, if we require the subsets of k Equal Sum Subsets tobe disjoint and non-empty (rather than non-identical).2We allow multi-sets for this problem. The NP -completeness proof for this problem without allowing multi-setsis very similar to the one given in Theorem 4. However, it is more technical and therefore omitted.6

5 NP -completeness of Equal Sum Subsets Variations with Ad-ditional RequirementsAs a further class of NP -complete variations of Equal Sum Subsets, we study problems wherewe add speci�c requirements that a solution must ful�ll. This approach allows us to explorethe sphere of NP -completeness that forms around Equal Sum Subsets. We focused on quitenatural additional requirements. The problems are de�ned as follows:De�nition (Equal Sum Subsets with Enforced Element). Given a set of n numbersA = fa1; : : : ; ang, are there two disjoint subsets X; Y � A with an 2 X such that sum(X) =sum(Y )?De�nition (Equal Sum Subsets of Different Cardinality). Given a set of n numbersA = fa1; : : : ; ang, are there two disjoint nonempty subsets X; Y � A with jX j 6= jY j such thatsum(X) = sum(Y )?De�nition (Equal Sum Subsets of Different by One Cardinality). Given a set of nnumbers A = fa1; : : : ; ang, are there two disjoint subsets X; Y � A with jX j = jY j+ 1 such thatsum(X) = sum(Y )?De�nition (Equal Sum Subsets of Equal Cardinality). Given a set of n numbersA = fa1; : : : ; ang, are there two disjoint nonempty subsets X; Y � A with jX j = jY j suchthat sum(X) = sum(Y )?De�nition (Alternating Partial Partition). Given n pairs of numbers (u1; v1); : : : ; (un; vn),are there two disjoint nonempty sets of indices I and J such that Pi2I ui+Pj2J vj =Pi2I vi+Pj2J uj?The NP -completeness of the �rst three problems is shown by giving reductions from Al-ternating Partition. After that we reduce Equal Sum Subsetsto Alternating PartialPartition, and then the latter to Equal Sum Subsets of Equal Cardinality to establishthe NP -hardness of these two problems.Lemma 5. Alternating Partition �p Equal Sum Subsets with Enforced Element.Proof. Let (u1; v1); : : : ; (un; vn) be the input pairs for Alternating Partition. Let S =Pni=1(ui + vi), ai = huii � �n(i) and bi := hvii � �n(i) for all 1 � i � n, and c = hS2 i� 1n.As usual, we use a base large enough such that no carry digits occur.Let fai j 1 � i � ng [ fbi j 1 � i � ng [ fcg be the input for Equal Sum Subsetswith Enforced Element. Then c is the enforced element. There exists a solution for theAlternating Partition instance if and only if there exists a solution for the Equal SumSubsets with Enforced Element instance.\only if": Let I and J be a solution for Alternating Partition. ThenPi2I ui+Pj2J vj =S2 . We de�ne X := fcg and Y := fai j i 2 Ig [ fbj j j 2 Jg. Thensum(Y ) = Xi2I ai +Xj2J bj7

= Xi2I (huii� �n(i)) +Xj2J(hvji� �n(j))= hXi2I ui +Xj2J vji� (Xi2I �n(i) +Xj2J �n(j))= hS2 i� nXi=1 �n(i)= hS2 i� 1n= sum(X):\if": Let X; Y be a solution for the Equal Sum Subsets with Enforced Element instance.Assume w.l.o.g. c 2 X . All numbers in the input have n + 1 digits. For each index i 2f2; : : : ; n + 1g, only three numbers, namely c; ai and bi, have a one in the i'th digit, all othernumbers in the input have a zero in the i'th digit. For each digit the sum over all elements in Xand in Y yields the same result. Therefore, since c 2 X , exactly one of ai or bi will be in Y foreach 1 � i � n, and X = fcg, since any other element would add a second one in some digit i,which then could not be equalized by elements in Y . Summing up the �rst digit of all elementsin Y yields exactly the �rst digit of c, which is S2 . Thus, I = fi 2 f1; : : : ; ng j ai 2 Y g andJ = fj 2 f1; : : : ; ng j bj 2 Y g yields a solution for the Alternating Partition instance.Lemma 6. Alternating Partition �p Equal Sum Subsets of Different Cardinality.Proof (sketch) The proof follows along the lines of the previous reduction. Each number ai inone set enforces bi to be in the other set, and vice versa. Thus, they yield sets X and Y of equalcardinalities. Therefore, element c has to be in either X or Y .Lemma 7. Alternating Partition �p Equal Sum Subsets of Different by One Car-dinality.Proof. This proof is similar to the previous proofs, except that we add n dummy elements toblow up the cardinality of subset which contains c.Let (u1; v1); : : : ; (un; vn) be the input pairs forAlternating Partition. Let S :=Pni=1(ui+vi) and M := n � 2n+2. De�ne ai := huii� �n(i)� hMn i and bi := hvii� �n(i)� hMn i for all1 � i � n. De�ne c := hS2 i� 1n � hM � (2n � 1)i. For 1 � k � n, we de�ne dummy elementsdk = h0i� 0n � h2k�1i.As before, any partial partition with only ai's and bi's will have equal cardinality. Thus, cwill be in one of the sets, say X , and n of the ai's and bi's will be in the other set Y to achieveequal sums in the �rst n+ 1 digits of the elements in X and Y . To achieve an equal sum in thelast digit as well, dk must bebe in set X for all 1 � k � n.Lemma 8. Equal Sum Subsets �p Alternating Partial Partition.Proof. Given an instance of Equal Sum Subsets, i.e. a set of numbers A = fa1; : : : ; ang, wereduce it to an instance of Alternating Partial Partition by mapping each number ai toa pair (ui; vi) with ui = ai and vi = 0. Clearly, if there are disjoint sets X; Y � A such thatsum(X) = sum(Y ) then there are disjoint sets of indices I = fi j ai 2 Xg and J = fj j aj 2 Y g8

such thatPi2I ui +Pj2J vj =Pi2I vi +Pj2J uj . Conversely, if there is an alternating partialpartition of the resulting pairs, i.e. appropriate sets of indices I; J , then the sets X = fai j i 2 Igand X = faj j j 2 Jg form a partial partition of the original set A.Lemma 9. Alternating Partial Partition �p Equal Sum Subsets of Equal Cardi-nality.Proof. Given an instance of Alternating Partial Partition we map each pair (ui; vi) totwo numbers ai = huii � �n(i), a0i = hvii � �n(i); i.e., we make new numbers with ui (resp.vi) as the most signi�cant digits, followed by n digits, the i-th of which is a 1 and all therest are 0's. We then set A to consist of all ai's and all a0i's. For the numbers we use baseB = Pni=1(ui + vi) + 1, which is su�ciently large such that adding any subset of numbers inA never gives carry digits. Thus, we can have an equal cardinality partial partition in A if andonly if for each ai on one side there is a0i on the other side, and vice versa, since only ai and a0ihave a one in the i+ 1'th digit. This is equivalent to having an alternating partial partition inthe original instance.From the previous lemmas and the fact that the problems are obviously in NP , we get thefollowing:Theorem 10. The problemsAlternating Partial Partition,Equal Sum Subsets of Equal Cardinality,Equal Sum Subsets of Different Cardinality,Equal Sum Subsets of Different by One Cardinality, andEqual Sum Subsets with Enforced Elementare NP -complete.6 NP -completeness of Finding Equal Sum Subsets from TwoSets (and its Variations)As a last set of NP -complete problems, we investigate Equal Sum Subsets from Two Setsand its variations.De�nition (Equal Sum Subsets from Two Sets). Given two sets of numbers A = fa1; : : : ; angand B = fb1; : : : ; bmg, are there two nonempty subsets U � A and V � B such that sum(U) =sum(V )?We study this problem in order to explore the limits of the sphere ofNP -completeness aroundAlternating Partial Partition to which the Equal Sum Subsets from Two Sets isclosely related. Alternating Partial Partition is the \partial" equivalent of AlternatingPartition, which is an important, well-known variation of Partition (see [3]). We show NP -completeness of Equal Sum Subsets from Two Sets by proposing a reduction from SubsetSum, which is de�ned as follows: Given a set of n numbers P = fp1; : : : ; png and a number S,is there a subset X � P such that sum(X) = S?Lemma 11. Subset Sum �p Equal Sum Subsets from Two Sets.9

Proof. Let fp1; : : : ; png and S be an instance of Subset Sum. Let A := fp1; : : : ; png andB := fSg be an instance of Equal Sum Subsets from Two Sets. If X is a solution for theSubset Sum instance, then X � A and sum(X) = S. Any solution U � A and V � B forthe Equal Sum Subsets from Two Sets instance will have V = B = fSg, and thereforesum(U) = S. Thus, a solution for the Subset Sum instance transforms easily in a solution forthe Equal Sum Subsets from Two Sets instance, and vice versa.In an approach similar to the one followed in Section 5, we de�ne restricted variations ofEqual Sum Subsets from Two Sets. We present NP -completeness results that give insightas to how far NP -completeness goes.De�nition (Equal Sum Subsets of Equal Cardinality from Two Sets). Given twosets of numbers A = fa1; : : : ; ang and B = fb1; : : : ; bmg, are there two nonempty subsets U � Aand V � B with jU j = jV j such that sum(U) = sum(V )?Lemma 12. Subset Sum �p Equal Sum Subsets of Equal Cardinality from TwoSets.Proof. Given an instance fp1; : : : ; png and S of Subset Sum we construct an instance of EqualSum Subsets of Equal Cardinality from Two Sets, i.e. sets A and B as follows:set A set Ba1 := hp1; 1; 0i b1 := h0; 1; 0i... ...ai := hpi; i; 0i bi := h0; i; 0i... ...an := hpn; n; 0i bn := h0; n; 0ian+1 := h0; 0; 1i bn+1 := hS; 0; 1iWe will show that there is a set X � fp1; : : : ; png such that sum(X) = S if and only if thereare nonempty sets U � A and V � B such that jU j = jV j and sum(U) = sum(V ).\only if": If there is a set X � fp1; : : : ; png such that sum(X) = S then, by de�ning U = fai jxi 2 Xg [ fan+1g and V = fbi j xi 2 Xg [ fbn+1g we have that sum(U) = sum(V ) = hS; k; 1i,where k =Pxi2X i.\if": Assume that nonempty sets U � A and V � B exist such that jU j = jV j and sum(U) =sum(V ). Then bn+1 2 V is necessary to have equal sums in the �rst digit. This implies thatthere are ai's in U such that sum(fpi j ai 2 Ug) = S, i.e., the corresponding pi's form a solutionfor the original Subset Sum instance.The following variation asks for two equal sum subsets that have disjoint indices:De�nition (Equal Sum Subsets with Disjoint Indices from Two Sets). Given two setsof n numbers A = fa1; : : : ; ang and B = fb1; : : : ; bng, are there two nonempty sets of indicesI; J � f1; : : : ; ng with I \ J = ; such that Pi2I ai =Pj2J bj?Lemma 13. Equal Sum Subsets from Two Sets �p Equal Sum Subsets with DisjointIndices from Two Sets. 10

Proof. (Sketch) Given an instance A = fa1; : : : ; ang and B = fb1; : : : ; bng of Equal Sum Sub-sets from Two Sets, we can construct an instance of Equal Sum Subsets with DisjointIndices from Two Sets (A0; B0) as follows:set A0 set B081 � i � n : a0i := haii� 0n � 0n b0i := h0i� �n(i)� 0n81 � i � n : a0n+i := h0i� 0n � �n(i) b0n+i := hbii� 0n � 0nIt is easy to see that there are two equal sum subsets of A and B if and only if there equalsum subsets of A0 and B0 with disjoint indices, since only subsets of the �rst n numbers in A0and the last n numbers in B0 can yield equal sums.An even more restricted variation asks for subsets with disjoint indices that cover the wholeset of indices.De�nition (Equal Sum Subsets with Disjoint Covering Indices from Two Sets).Given two sets of n numbers A = fa1; : : : ; ang and B = fb1; : : : ; bng, are there two sets ofindices I; J � f1; : : : ; ng with I \ J = ; and I [ J = f1; : : : ; ng such that Pi2I ai =Pj2J bj?Lemma 14. Partition �p Equal Sum Subsets with Disjoint Covering Indices fromTwo Sets.Proof. Given an instance of Partition fa1; : : : ; ang we construct an instance of Equal SumSubsets with Disjoint Covering Indices from Two Sets by setting A0 = B0 = A. Now,if A can be partitioned into X and Y , then choosing the corresponding elements in A0 andB0 respectively gives us a solution for the Equal Sum Subsets with Disjoint CoveringIndices from Two Sets instance, and vice versa.We �nally examine the variation where we want the sets of indices to be identical.De�nition (Equal Sum Subsets with Identical Indices from Two Sets). Given twosets of n numbers A = fa1; : : : ; ang and B = fb1; : : : ; bng, is there a nonempty set of indicesI � f1; : : : ; ng such that Pi2I ai =Pi2I bi?Lemma 15. Subset Sum �p Equal Sum Subsets with Identical Indices from TwoSets.Proof. We use the same reduction as in Lemma 12. It su�ces to observe that any two equalsum subsets U � A and V � B either have identical indices or there is always V 0 � B such thatsum(V ) = sum(V 0) = sum(U) and V 0 has identical indices with U .From the previous lemmas and the fact that the problems are obviously in NP , we get thefollowing:Theorem 16. The problemsEqual Sum Subsets from Two Sets,Equal Sum Subsets of Equal Cardinality from Two Sets,Equal Sum Subsets with Disjoint Indices from Two Sets,Equal Sum Subsets with Disjoint Covering Indices from Two Sets, andEqual Sum Subsets with Identical Indices from Two Setsare NP -complete. 11

7 ConclusionsWe have presented NP -completeness results for many natural and interesting variations ofEqual Sum Subsets.The results in this paper are only a �rst step in investigating variations of Equal SumSubsets. A line of future research is to further explore the brink of NP -completeness in termsof Equal Sum Subsets variations. Potential examples of such variations are: a variation withadditive factor (instead of multiplicative) or a variation in which the required cardinalities of thetwo subsets are given as part of the input. Moreover, cases where the input contains negativenumbers deserve consideration. It would also be interesting to study some of our variations intheir full partition counterparts.AcknowledgmentsWe would like to thank Christoph Amb�uhl, Zsuzsanna Lipt�ak, Paolo Penna, and Peter Widmayerfor their help in this work.References[1] C. Bazgan, M. Santha and Zs. Tuza; E�cient approximation algorithms for the Subset-SumEquality problem; Proc. ICALP'98, pp. 387{396.[2] Mark Cieliebak, Stephan Eidenbenz, Aris Pagourtzis, Paolo Penna; Variations of the PartialDigest Problem; Manuscript, to be published 2002.[3] M.R. Garey and D.S. Johnson; Computers and Intractability: A Guide to the Theory ofNP-completeness; Freeman, San Fransisco, 1979.[4] R.M. Karp; Reducibility among combinatorial problems; in R.E. Miller and J.W. Thatcher(eds.), Complexity of Computer Computations, Plenum Press, New York, pp. 85 { 103,1972.[5] S. Martello and P. Toth; Knapsack Problems; John Wiley & Sons, Chichester, 1990.[6] C.H. Papadimitriou; On the complexity of the parity argument and other ine�cient proofsof existence; Journal of Computer and System Sciences, 48, pp. 498 { 532, 1994.[7] C.H. Papadimitriou; Computational Complexity ; Addison-Wesley Publishing Company,1994.[8] P. Pevzner; Computational Molecular Biology ; MIT Press, 2000.[9] G.J. Woeginger and Z.L. Yu; On the equal-subset-sum problem; Information ProcessingLetters, 42(6), pp. 299{302, 1992. 12