TOPICS
Search

Subset Sum Problem


The subset sum problem refers to two problems.

The first ("given sum problem") asks for a subset of the positions in a list of integers whose values have a given sum. It is an integer relation problem with selection coefficients 0 or 1 after adjoining the negative of the target sum with its coefficient fixed at 1.

The second ("same sum problem") is the problem of finding a set of n distinct positive real numbers with as large a collection as possible of subsets with the same sum (Proctor 1982).

The same sum problem was solved by Stanley (1980, pp. 178-179) using the tools of algebraic geometry, with the answer given for n numbers by the first n positive integers: {1,2,...,n}. Proctor (1982, pp. 721-723) gave an elementary proof of this result. The maximal numbers of subsets of {1,2,...,n} having the same sum for n=1, 2, ... are 1, 1, 2, 2, 3, 5, 8, 14, 23, ... (OEIS A025591).

The decision version of the given sum problem asks whether such a subset exists and is an NP-complete problem for binary-encoded inputs. Finding a witness is the related NP-hard problem (Lagarias and Odlyzko 1985, p. 229). For small cases, the given sum problem can be solved using generating functions. Consider the number of ways c_(m,s) to select m out of M given indexed integers a_1, ..., a_M such that their sum equals s, and define the generating function

 G(x,y)=product_(k=1)^M(1+x^(a_k)y).
(1)

Upon expanding in powers of y, this becomes

 G(x,y)=sum_(m=0)^MG_m(x)y^m.
(2)

But as a result of the exponent laws, in particular x^mx^n=x^(m+n), G_m(x) is precisely the desired generating function

 G_m(x)=sum_(s)c_(m,s)x^s.
(3)

Here G_m(x) is a Laurent polynomial, and is a polynomial when every a_k>=0.

For example, consider the problem of picking m objects from the set {1,2,3,4,5}. The generating function G(x,y) is

 G(x,y)=y^5x^(15)+(x^(14)+x^(13)+x^(12)+x^(11)+x^(10))y^4+(x^(12)+x^(11)+2x^(10)+2x^9+2x^8+x^7+x^6)y^3+(x^9+x^8+2x^7+2x^6+2x^5+x^4+x^3)y^2+(x^5+x^4+x^3+x^2+x)y+1.
(4)

So, for example, selecting m=3 objects has the generating function

G_3(x)=sum_(s)c_(3,s)x^s
(5)
=x^(12)+x^(11)+2x^(10)+2x^9+2x^8+x^7+x^6,
(6)

so the number of ways of picking three of the integers 1 through 5 and having them sum to s=12, 11, ..., 6 are the coefficients c_(3,s) of G_3(x), namely 1, 1, 2, 2, 2, 1, and 1. These solutions are summarized in the following table.

ssolutions
6(1, 2, 3)
7(1, 2, 4)
8(1, 2, 5), (1, 3, 4)
9(1, 3, 5), (2, 3, 4)
10(1, 4, 5), (2, 3, 5)
11(2, 4, 5)
12(3, 4, 5)

An explicit example originally proposed by Pólya (1956) asks for the number of ways to make change from an American dollar (using pennies, nickels, dimes, quarters, and half-dollars). The answer of 292 is provided as the coefficient of the x^(100) term in the series

 sum_(k=0)^inftyP_kx^k=1/((1-x)(1-x^5)(1-x^(10))(1-x^(25))(1-x^(50)))
(7)

for |x|<1 (Borwein and Bailey 2003, p. 21).

Chen et al. (2026) reported a deterministic algorithm for the vector version of the given sum problem. For fixed integer d>=1 and epsilon>0, an explicitly listed multiset of n vectors with integer coordinates in [-N,N]^d can be tested for a subset with a specified vector sum in O_(d,epsilon)(n+N^(d+epsilon)) word-RAM time, for N>=2. The bound is polynomial in the coordinate bound N, not in its binary encoding length.

Chen et al. (2026) attribute the one-dimensional proof strategy to the authors and substantial proof development to GPT. They report that the deterministic multidimensional extension was obtained by GPT and supply a Lean formalization.


See also

Abundant Number, Grid Shading Problem, Integer Relation, Knapsack Problem, Lattice Reduction, Postage Stamp Problem, Pseudoperfect Number, Stöhr Sequence, Subset Sum, Weird Number

Explore with Wolfram|Alpha

References

Borwein, J. and Bailey, D. Mathematics by Experiment: Plausible Reasoning in the 21st Century. Wellesley, MA: A K Peters, pp. 22-24, 2003.Chen, L.; Mao, Y.; and Zhang, G. "Subset Sum and Integer Programming Feasibility Test in Near-Optimal Time." 9 Oct 2026. https://arxiv.org/abs/2610.12953.Coster, M. J.; Joux, A.; LaMacchia, B. A.; Odlyzko, A. M.; Schnorr, C. P.; and Stern, J. "Improved Low-Density Subset Sum Algorithms." Comput. Complex. 2, 111-128, 1992.Coster, M. J.; LaMacchia, B. A.; Odlyzko, A. M.; and Schnorr, C. P. "An Improved Low-Density Subset Sum Algorithm." In Advances in Cryptology-EUROCRYPT '91 (Proc. Workshop on the Theory and Application of Cryptographic Techniques, Brighton, UK, April 8-11, 1991) (Ed. D. W. Davies). Berlin, Germany: Springer-Verlag, pp. 54-67, 1991. https://doi.org/10.1007/3-540-46416-6_4.Ferguson, H. R. P. and Bailey, D. H. "A Polynomial Time, Numerically Stable Integer Relation Algorithm." RNR Techn. Rept. RNR-91-032, Jul. 14, 1992.Lagarias, J. C. and Odlyzko, A. M. "Solving Low-Density Subset Sum Problems." J. ACM 32, 229-246, 1985.Pólya, G. "On Picture-Writing." Amer. Math. Monthly 63, 689-697, 1956.Proctor, R. A. "Solution of Two Difficult Combinatorial Problems with Linear Algebra." Amer. Math. Monthly 89, 721-734, 1982.Schnorr, C. P. and Euchner, M. "Lattice Basis Reduction: Improved Practical Algorithms and Solving Subset Sum Problems." In Fundamentals of Computation Theory: Proceedings of the 8th International Conference, FCT '91 Gosen, Germany, September 9-13, 1991 (Ed. L. Budach). Berlin, Germany: Springer-Verlag, pp. 68-85, 1991. https://doi.org/10.1007/3-540-54458-5_51.Sloane, N. J. A. Sequence A025591 in "The On-Line Encyclopedia of Integer Sequences."Stanley, R. P. "Weyl Groups, the Hard Lefschetz Theorem, and the Sperner Property." SIAM J. Alg. Disc. Meth. 1, 168-184, 1980. https://doi.org/10.1137/0601021.

Referenced on Wolfram|Alpha

Subset Sum Problem

Cite this as:

Weisstein, Eric W. "Subset Sum Problem." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/SubsetSumProblem.html

Subject classifications