0% found this document useful (0 votes)
148 views1 page

Module 1 Backtracking Sum of Subset

The document describes using a backtracking algorithm to find all subsets of numbers from an array that sum to a target value, by recursively adding elements, checking if the subset sums to the target, and backtracking by removing elements if it exceeds the target sum or reaches the end without matching. The proposed algorithm starts with an empty set, adds elements to the set one by one, checks if it sums to the target value, and backtracks the set if it doesn't sum or reaches the end of the list.

Uploaded by

Badri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
148 views1 page

Module 1 Backtracking Sum of Subset

The document describes using a backtracking algorithm to find all subsets of numbers from an array that sum to a target value, by recursively adding elements, checking if the subset sums to the target, and backtracking by removing elements if it exceeds the target sum or reaches the end without matching. The proposed algorithm starts with an empty set, adds elements to the set one by one, checks if it sums to the target value, and backtracks the set if it doesn't sum or reaches the end of the list.

Uploaded by

Badri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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.

You might also like