Subset Sum Problem (Backtracking)

Find if there exists a subset of given array that sums to a target value

Subset Sum Problem

The Subset Sum problem asks whether there exists a subset of a given set of integers that sums to a specific target value.

Theory & Concepts

Definition:

Given a set of positive integers and a target sum, determine if there exists a subset whose elements sum exactly to the target.

Key Points:

  • NP-Complete problem - no known polynomial solution
  • Backtracking explores all possible subset combinations
  • Pruning optimization: stop if current sum exceeds target
  • Can be solved using dynamic programming for optimization

Applications:

  • Partition problems in computer science
  • Resource allocation and budget planning
  • Cryptography and number theory
  • Combinatorial optimization problems

University Guidelines

Exam Weightage
6-8 marks Marks

Syllabus Coverage:

  • Subset sum problem formulation
  • Backtracking approach implementation
  • Include/exclude decision tree
  • Pruning strategies and optimization
  • Complexity analysis

Common Questions:

  • Find subset with given sum using backtracking
  • Trace algorithm execution with decision tree
  • Implement subset sum with pruning
  • Compare with dynamic programming approach

Exam Tips:

Show include/exclude decisions clearly
Demonstrate pruning when sum exceeds target
Draw decision tree for small examples
Mention exponential time complexity O(2^n)

Algorithm Details

O(2^n) - explores all possible subsets
Time Complexity
O(n) for recursion stack depth
Space Complexity

Algorithm Steps:

  1. 1Start with empty subset, index 0, sum 0
  2. 2For each element, make two recursive calls:
  3. 3 1. Include current element (add to subset and sum)
  4. 4 2. Exclude current element (move to next index)
  5. 5Base cases: sum equals target (found) or index >= array length
  6. 6Pruning: if current sum > target, stop exploration
  7. 7Return true if any path finds the target sum

Configure Subset Sum

Current Problem:

Array:
3[0]
34[1]
4[2]
12[3]
5[4]
2[5]
Target Sum:9
Array Sum:60

Search Results

🎯

Configure the array and target sum, then click "Find Subset" to start the search