What is the Sum of Subset problem? Explain with an example.

What is the Sum of Subset problem? Explain with an example.

Attempted by 1 students.

Show answer & explanation

Introduction

The Sum of Subset problem is a classic backtracking problem where the goal is to find one or more subsets of a given set of numbers whose sum equals a specified target value. It is widely used to demonstrate backtracking, as it involves building a solution incrementally and abandoning ("backtracking") a path as soon as it is determined that it cannot lead to a valid solution.

Approach

Starting with an empty subset, elements are added one by one. At each step, if the current sum equals the target, the subset is recorded as a solution. If the sum exceeds the target, that path is discarded, and the algorithm backtracks to try a different combination.

Example

Consider the set S = {5, 10, 12, 13, 15, 18} and target sum = 30.

One possible solution subset is {5, 12, 13}, since 5 + 12 + 13 = 30.

Another solution could be {5, 10, 15}, since 5 + 10 + 15 = 30.

The algorithm explores different combinations systematically, using a state-space tree, and prunes branches where the partial sum already exceeds the target, improving efficiency compared to brute-force methods.

Application

This problem is used in resource allocation, cryptography, and financial computations where selecting specific combinations meeting a target value is required.

Explore the full course: Up Lt Grade Assistant Teacher 2025

Loading lesson…