Tool to calculate the sum of subsets, solve the subset sum problem, and test combinations of numbers quickly and for free online.
Subset Sum - dCode
Tag(s) : Arithmetics, Combinatorics
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
The subset sum problem (SSP) is a classic problem in theoretical computer science and combinatorial optimization.
It consists of determining whether there exists a subset of a given set of integers whose sum equals a given target value.
Formally, given a set $ A = \{n_1, n_2, \ldots, n_n\} $ and a target $ N $, the goal is to find a subset $ B \subseteq A $ such that the sum of the elements of $ B $ equals $ N $, i.e., $ \sum n_{i \subseteq B} = N $
Example: $ S = \{3, 5, 2, 7\} $ and $ N = 10 $, then the subset $ \{3, 7\} $ is a solution, since $ 3 + 7 = 10 $
— Naive approach (brute force): Test all possible combinations of subsets. This method has an exponential complexity of $ O(2^n) $, making it inefficient for large sets.
— Dynamic programming: Use a table to store the sums feasible with the subsets. The complexity is $ O(n \times N) $, where $ n $ is the size of the set and $ N $ is the target value.
— Approximation algorithms: For large instances, algorithms like Meet-in-the-Middle reduce the complexity to $ O(2^{n/2}) $
The knapsack problem generalizes the sum of subsets by assigning a weight and a value to each element.
In the knapsack problem, the goal is to maximize the total value without exceeding a given capacity, whereas the sum of subsets focuses solely on the sum of the elements.
By allowing repetition of elements in the sum of subsets, then the subset problem is a variant of integer partitions restricted to a given set.
dCode retains ownership of the "Subset Sum" source code. Any algorithm for the "Subset Sum" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Subset Sum" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Subset Sum" or any other element are not public (except explicit open source licence). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.
The content of the page "Subset Sum" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source (Creative Commons CC-BY free distribution license).
Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).
To cite dCode.fr on another website, use the link:
In a scientific article or book, the recommended bibliographic citation is: Subset Sum on dCode.fr [online website], retrieved on 2026-01-11,