1 Introduction
Given a (multi) set of positive integers and an integer target value , the SubsetSum problem is to decide if there is a (multi) subset of that sums up to . The SubsetSum is a classical problem with relatively long history. It is one of Karp’s original NPcomplete problems [14], closely related to other fundamental NPcomplete problems such as Knapsack [7], Constrained Shortest Path [2], and various other graph problems with cardinality constraints [9, 12, 16]. Furthermore, it is one of the initial weakly NPcomplete problems; problems that admit pseudopolynomial time algorithms – a classification identified by Garey and Johnson in [11]. The first such algorithm was given in 1957 ^{1}^{1}1 Note that Bellman wrote this paper before the definition of pseudopolynomial time algorithms was provided by Garey and Johnson in 1977. by Bellman, who showed how to solve the problem in time using dynamic programming [3].
The importance of the SubsetSum problem in computer science is further highlighted by its role in teaching. Both the problem and its algorithm have been included in undergraduate algorithms courses’ curriculums and textbooks for several decades ([6, Chapter 34.5.5], used as archetypal examples for introducing the notions of weak NPcompleteness and pseudopolynomial time algorithms to college students [15, Chapter 8.8]. In addition, the conceptually simple problem statement makes this problem a great candidate in the study of NPcompleteness [8, Chapter 8.1]), and, finally, Bellman’s algorithm is also often introduced in the context of teaching dynamic programming [10, Chapter 5.6].
Extensive work has been done on finding better and faster pseudopolynomial time algorithms for the SubsetSum (for a collection of previous results see [17, Table 1.1]). The first improvement on the running time was a time algorithm by [18], almost two decades go. Recently, the stateoftheart was improved significantly to time by the authors [17]. Shortly after, in a follow up work, the running time was further improved to time by Bringmann [5] – the algorithm is randomized and somewhat involved. Abboud et al. [1] showed that it is unlikely that any SubsetSum algorithm runs in time , for any constant and target number , as such an algorithm would imply that the Strong Exponential Time Hypothesis (SETH) of Impagliazzo and Paturi [13] is false.
In this paper, we present a new simple algorithm for the SubsetSum
problem. The algorithm follows the divideandconquer paradigm and uses the Fast Fourier Transform (), matching the best deterministic running time
of [17] with a cleaner and more straightforward analysis. The algorithm partitions the input by congruence into classes, computes the subset sums of each class recursively, and combines the results. We believe this new simple algorithm, although not improving upon the stateoftheart, reduces the conceptual complexity of the problem and improves our understanding of it. We believe the new algorithm can be used in teaching as an example of a pseudopolynomial time algorithm for the SubsetSum problem, as well as a striking example of applying to a seemingly unrelated problem.Comparison to previous work
Our previous algorithm [17] used a more complicated divideandconquer strategy that resulted in forming sets of two different types, that had to be handled separately. Bringmann’s algorithm [5] uses randomization and a twostage colorcoding process. Both algorithms are significantly more complicated than the one presented here.
2 Preliminaries
Let denote the set of integers in the interval . Given a set , let and denote the set of all subset sums of up to by
and the set of all subset sums of up to with cardinality information by
Let , be two sets, the set of pairwise sums of and up to is denoted by
If , are sets of points in the plane, then
Observe, that if and are two disjoint sets, then .
Next, we define two generalizations of the SubsetSum problem. Both can be solved by the new algorithm.
Note that the case where the input is a multiset can be reduced to the case of a set with little loss in generality and running time (see [17, Section 2.2]), hence for simplicity of exposition we assume the input is a set throughout the paper.
3 The algorithm
Here, we show how to solve AllSubsetSums in time. Clearly, computing all subset sums up to also decides SubsetSum with target value .
3.1 Building blocks
The following wellknown lemma describes how to compute pairwise sums between sets in almost linear time, in the size of their ranges, using .
[Computing pairwise sums ] The following are true:

Given two sets , , one can compute in time.

Given sets , one can compute in time.

Given two sets of points , , one can compute in time.
Proof.
(A) Let be the characteristic polynomial of . Construct, in a similar fashion, the polynomial (for the set ) and let . Observe that for , the coefficient of in is nonzero if and only if . Using , one can compute the polynomial in time, and extract from it.
(B) Let , and let , for . Compute each , from and , in time using part (A). The total running time is .
(C) As in (A), let and be the characteristic polynomials of and , respectively, and let . For the coefficient of is nonzero if and only if . One can compute the polynomial by a straightforward reduction to regular (see multidimensional [4, Chapter 12.8]), in time, and extract from it. ∎
The next lemma shows how to answer AllSubsetSums quickly, originally shown by the authors in [17], the proof is included for completeness.
[AllSubsetSums [17]] Let be a given set of elements. One can compute, in time, the set , which includes all subset sums of up to with cardinality information.
Proof.
Partition into two sets and of roughly the same size. Compute and recursively, and observe that , . Finally, note that . Applying Lemma 3.1.C yields .
The running time follows the recursive formula , which is , proving the claim. ∎
Next, we show how to compute the subset sums of elements in a congruence class quickly.
Let , with . Given a set of size , one can compute in time.
Proof.
An element can be written as . Let . As such, for any subset of size , we have that
In particular, a pair corresponds to a set of size , such that . The set in turn corresponds to the set . By the above, the sum of the elements of is . As such, compute , using the algorithm of Lemma 3.1, and return as the desired result. ∎
3.2 Algorithm
3.3 Result
[AllSubsetSums] Let be a given set of elements. One can compute, in time, the set , which contains all subset sums of up to .
Proof.
AllSubsetSums is a generalization of SubsetSum, so the algorithm of subsection 3.3 applies to it.
References
 [1] Amir Abboud, Karl Bringmann, Danny Hermelin, and Dvir Shabtay. SETHbased lower bounds for subset sum and bicriteria path. CoRR, abs/1704.04546, 2017. URL: http://arxiv.org/abs/1704.04546, arXiv:1704.04546.
 [2] Kyriakos Axiotis and Christos Tzamos. Capacitated dynamic programming: Faster knapsack and graph algorithms. CoRR, abs/1802.06440, 2018. URL: http://arxiv.org/abs/1802.06440, arXiv:1802.06440.
 [3] Richard Bellman. Notes on the theory of dynamic programming IV  maximization over discrete sets. Naval Research Logistics Quarterly, 3(12):67–70, 1956. URL: http://dx.doi.org/10.1002/nav.3800030107, doi:10.1002/nav.3800030107.
 [4] Richard E. Blahut. Fast Algorithms for Digital Signal Processing. AddisonWesley Longman Publishing Co., Inc., Boston, MA, USA, 1st edition, 1985.
 [5] Karl Bringmann. A nearlinear pseudopolynomial time algorithm for subset sum. In Proceedings of the TwentyEighth Annual ACMSIAM Symposium on Discrete Algorithms, pages 1073–1084. Society for Industrial and Applied Mathematics, 2017.
 [6] Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Third Edition. The MIT Press, 3rd edition, 2009.
 [7] George B. Dantzig. Discretevariable extremum problems. Operations Research, 5(2):266–277, 1957. URL: http://www.jstor.org/stable/167356.
 [8] Sanjoy Dasgupta, Christos H. Papadimitriou, and Umesh Vazirani. Algorithms. McGrawHill, Inc., New York, NY, USA, first edition, 2008.
 [9] David Eppstein. Minimum range balanced cuts via dynamic subset sums. Journal of Algorithms, 23(2):375 – 385, 1997. URL: http://www.sciencedirect.com/science/article/pii/S019667749690841X, doi:http://dx.doi.org/10.1006/jagm.1996.0841.
 [10] Jeff Erickson. Algorithms, etc., January 2015. Course materials, 1250 pages. URL: https://jeffe.cs.illinois.edu/teaching/algorithms/.
 [11] Michael R Garey and David S Johnson. “Strong” NPCompleteness Results: Motivation, Examples, and Implications. Journal of the ACM (JACM), 25(3):499–508, 1978.
 [12] Venkatesan Guruswami, Yury Makarychev, Prasad Raghavendra, David Steurer, and Yuan Zhou. Finding almostperfect graph bisections. In Innovations in Computer Science  ICS 2010, Tsinghua University, Beijing, China, January 79, 2011. Proceedings, pages 321–337, 2011. URL: http://conference.itcs.tsinghua.edu.cn/ICS2011/content/papers/11.html.
 [13] Russell Impagliazzo and Ramamohan Paturi. On the complexity of ksat. Journal of Computer and System Sciences, 62(2):367 – 375, 2001. URL: http://www.sciencedirect.com/science/article/pii/S0022000000917276, doi:https://doi.org/10.1006/jcss.2000.1727.
 [14] Richard M. Karp. Reducibility among combinatorial problems. In Raymond E. Miller, James W. Thatcher, and Jean D. Bohlinger, editors, Complexity of Computer Computations, The IBM Research Symposia Series, pages 85–103. Springer US, 1972. URL: http://dx.doi.org/10.1007/9781468420012_9, doi:10.1007/9781468420012_9.
 [15] Jon Kleinberg and Eva Tardos. Algorithm Design. AddisonWesley Longman Publishing Co., Inc., Boston, MA, USA, 2005.
 [16] Bettina Klinz and Gerhard J. Woeginger. A note on the bottleneck graph partition problem. Networks, 33(3):189–191, 1999. URL: http://dx.doi.org/10.1002/(SICI)10970037(199905)33:3<189::AIDNET5>3.0.CO;22, doi:10.1002/(SICI)10970037(199905)33:3<189::AIDNET5>3.0.CO;22.
 [17] Konstantinos Koiliaris and Chao Xu. A faster pseudopolynomial time algorithm for subset sum. In Proceedings of the TwentyEighth Annual ACMSIAM Symposium on Discrete Algorithms, pages 1062–1072. SIAM, 2017.
 [18] David Pisinger. Linear time algorithms for knapsack problems with bounded weights. Journal of Algorithms, 33(1):1 – 14, 1999.
Comments
There are no comments yet.