Department of Computer Science and Engineering
Department of Computer Science and Engineering
5.Find the sum of subset for { 5, 10, 12, 13, 15, 18} where M=30 and draw state space tree.
Ans - What you're solving for
Finding subsets of a given set that sum to a target value and representing the search process as a state-space tree.
Use backtracking to explore all possible subsets and check if their sum equals .
1. Step 1 Start with an empty subset and a current sum of .
o Current subset: \{\}
o Current sum:
2. Step 2 Consider the first element ).
o Case 1: Include .
Current subset:
Current sum:
o Case 2: Exclude .
Current subset: \{\}
Current sum:
3. Step 3 Consider the next element ).
o Case 1 (from Step 2, Case 1): Include .
Current subset:
Current sum:
o Case 2 (from Step 2, Case 1): Exclude .
Current subset:
Current sum:
o Case 3 (from Step 2, Case 2): Include .
Current subset:
Current sum:
o Case 4 (from Step 2, Case 2): Exclude .
Current subset: \{\}
Current sum:
4. Step 4 Continue this process for all elements.
o Explore all branches until either the sum equals or it's clear that the sum cannot reach .
5. Step 5 Identify the subsets that sum to .
o
o
o
6. Step 6 Draw the state-space tree.
o The root node is the empty set.
o Each level represents a decision for an element.
o Leaf nodes represent either a solution or a dead end.
Solution
.
6.State and explain the Masters theorem with example.
Ans - Masters theorem is one of the many methods that are applied to calculate time complexities of algorithms. In analysis, time
complexities are calculated to find out the best optimal logic of an algorithm. Masters theorem is applied on recurrence relations.
But before we get deep into the masters theorem, let us first revise what recurrence relations are −
Recurrence relations are equations that define the sequence of elements in which a term is a function of its preceding term. In algorithm
analysis, the recurrence relations are usually formed when loops are present in an algorithm.