ArticleslgStudy

science

Subset sum problem

Subset sum problem is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Subset sum problem rather than just read about it. In short: The subset sum problem (SSP) is a decision problem in computer science. In its most general formulation, there is a multiset S {\displaystyle S} of integers and a target-sum T {\displaystyle T} , and the question is to decide whether any subset of the integers sum to precisely T {\displaystyle T} .

Key takeaways

  • Subset sum problem belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Subset sum problem to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Subset sum problem from memory before moving on to harder problems.

Reference excerpt

The subset sum problem (SSP) is a decision problem in computer science. In its most general formulation, there is a multiset S {\displaystyle S} of integers and a target-sum T {\displaystyle T} , and the question is to decide whether any subset of the integers sum to precisely T {\displaystyle T} . The problem is known to be NP-complete. Moreover, some restricted variants of it are NP-complete too, for example:

The variant in which all inputs are positive. The variant in which inputs may be positive or negative, and T = 0 {\displaystyle T=0} . For example, given the set { − 7 , − 3 , − 2 , 9000 , 5 , 8 } {\displaystyle \{-7,-3,-2,9000,5,8\}} , the answer is yes because the subset { − 3 , − 2 , 5 } {\displaystyle \{-3,-2,5\}} sums to zero. The variant in which all inputs are positive, and the target sum is exactly half the sum of all inputs, i.e., T = 1 2 ( a 1 + ⋯ + a n ) {\displaystyle T={\frac {1}{2}}(a_{1}+\dots +a_{n})} . This special case of SSP is known as the partition problem. SSP can also be regarded as an optimization problem: find a subset whose sum is at most T, and subject to that, as close as possible to T. It is NP-hard, but there are several algorithms that can solve it reasonably quickly in practice. SSP is a special case of the knapsack problem and of the multiple subset sum problem.

Computational hardness The time complexity of SSP depends on two parameters:

n - the number of input integers. If n is a small fixed number, then an exhaustive search for the solution is practical. L - the precision of the problem, stated as the number of binary place values that it takes to state the problem. If L is a small fixed number, then there are dynamic programming algorithms that can solve it exactly. As both n and L grow large, SSP is NP-hard. The complexity of the best known algorithms is exponential in the smaller of the two parameters n and L. The problem is NP-hard even when all input integers are positive (and the target-sum T is a part of the input). This can be proved by a direct reduction from 3SAT. It can also be proved by reduction from 3-dimensional matching (3DM):

We are given an instance of 3DM, where the vertex sets are W, X, Y. Each set has n vertices. There are m edges, where each edge contains exactly one vertex from each of W, X, Y. Denote L := ceiling(log2(m+1)), so that L is larger than the number of bits required to represent the number of edges. We construct an instance of SSP with m positive integers. The integers are described by their binary representation. Each input integer can be represented by 3nL bits, divided into 3n zones of L bits. Each zone corresponds to a vertex. For each edge (w,x,y) in the 3DM instance, there is an integer in the SSP instance, in which exactly three bits are "1": the least-significant bits in the zones of the vertices w, x, and y. For example, if n=10 and L=3, and W=(0,...,9), X=(10,...,19), Y=(20,...,29), then the edge (0, 10, 20) is represented by the number (20+230+260). The target sum T in the SSP instance is set to an integer with "1" in the least-significant bit of every zone, that is, (20+21+...+23n-1). If the 3DM instance has a perfect matching, then summing the corresponding integers in the SSP instance yields exactly T. Conversely, if the SSP instance has a subset with sum exactly T, then, since the zones are sufficiently large so that there are no "carries" from one zone to the next, the sum must correspond to a perfect matching in the 3DM instance. The following variants are also known to be NP-hard:

The input integers can be both positive and negative, and the target-sum T = 0. This can be proved by reduction from the variant with positive integers. Denote that variant by SubsetSumPositive and the current variant by SubsetSumZero. Given an instance (S, T) of SubsetSumPositive, construct an instance of SubsetSumZero by adding a single element with value −T. Given a solution to the SubsetSumPositive instance, adding the −T yields a solution to the SubsetSumZero instance. Conversely, given a solution to the SubsetSumZero instance, it must contain the −T (since all integers in S are positive), so to get a sum of zero, it must also contain a subset of S with a sum of +T, which is a solution of the SubsetSumPositive instance. The input integers are positive, and T = sum(S)/2. This can also be proved by reduction from the general variant; see partition problem. The analogous counting problem #SSP, which asks to enumerate the number of subsets summing to the target, is #P-complete.

Exponential time algorithms There are several ways to solve SSP in time exponential in n.

Inclusion–exclusion The most naïve algorithm would be to cycle through all subsets of n numbers and, for every one of them, check if the subset sums to the right number. The running time is of order O ( 2 n ⋅ n ) {\displaystyle O(2^{n}\cdot n)} , since there are 2 n {\displaystyle 2^{n}} subsets and, to check each subset, we need to sum at most n elements. The algorithm can be implemented by depth-first search of a binary tree: each level in the tree corresponds to an input number; the left branch corresponds to excluding the number from the set, and the right branch corresponds to including the number (hence the name Inclusion-Exclusion). The memory required is O ( n ) {\displaystyle O(n)} . The run-time can be improved by several heuristics:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Subset sum problem

Start with the simplest possible case. Write down what Subset sum problem claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Subset sum problem before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Subset sum problem ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Subset sum problem

In research
Subset sum problem appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Subset sum problem in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Subset sum problem is common in secondary-school and first-year university syllabi. It links to neighbouring topics Dynamic programming, Weakly NP-complete problems, so understanding it makes those chapters shorter.
In everyday life
Look for Subset sum problem outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Subset sum problem” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Subset sum problem in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Subset sum problem means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Subset sum problem out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Subset sum problem in simple terms?

The subset sum problem (SSP) is a decision problem in computer science. In its most general formulation, there is a multiset S {\displaystyle S} of integers and a target-sum T {\displaystyle T} , and the question is to decide whether any subset of the integers sum to precisely T {\displaystyle T} .

Why does Subset sum problem matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Subset sum problem?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Subset sum problem.

Tags

  • Dynamic programming
  • Weakly NP-complete problems

Keep exploring