Sum of Subset using Backtracking Technique – notes
Let S be an array of numbers (3, 5, 6, 7) and expected sum = 15.
Find every possible subset whose total is 15.
Bounding Conditions:
1. When a node that represents a subset whose sum equals the desired target_sum, terminate.
2. When a node that represents a subset whose sum exceeds the desired target_sum ,
backtrack. i.e., do not enter its sub-trees, go back to parent node.
We use backtracking approach. It is a recursive algorithm that uses brute force concept. The
term backtracking implies that if the current solution is not suitable, then move a step back
and try other solutions.
Proposed algorithm:
1. Start with an empty set.
2. Include the next element from list to set.
3. If the numbers in the set sum up to given target_sum, It is a solution set.
4. If the set doesn’t sum up to the target_sum or if we have reached the end of my_list, then
backtrack the set until we find a solution set.
5. If we get a feasible solution, go to step 2.
6. If we have traversed all the elements and if no backtracking is possible, then stop without
solution.