1.
Subset Sum using Backtracking:
Given S = {1, 3, 4, 5} and D = 11
Try all subsets using backtracking. Check sum = 11.
Checked: {1,3,4,5}=13 (Invalid), {1,3,4}=8 (Invalid), {3,4,5}=12 (Invalid)
No subset adds to 11. So, No valid subset found.
2. What is Backtracking + 4-Queens Problem:
Backtracking is trying possible solutions step-by-step and backtrack if fails.
4-Queens: Place 4 queens so no two attack each other.
One solution: Q at (1,2), (2,4), (3,1), (4,3)
Board:
_Q__
___Q
Q___
__Q_
3. Short Notes:
i. P and NP:
P = Solvable in polynomial time.
NP = Verifiable in polynomial time.
ii. NP-Complete:
Problems that are both in NP and as hard as any NP problem. If one is solved fast, all NP problems
can be.
4. Knapsack using Branch and Bound:
W = 16, Items: (10,100), (7,63), (8,56), (4,12)
Use value/weight ratio to sort: Item1:10, Item2:9, Item3:7, Item4:3
Select Item1 (10), Item2 (7) -> total weight = 17 (Too much)
Try: Item2 (7) + Item3 (8) = 15 (Valid) -> Value = 63+56=119
Best value = 119
5. Hamiltonian Circuit with Backtracking:
Start at any node. Try visiting all nodes once and return to start.
Backtrack if path repeats node or leads to dead-end.
Continue until full cycle is found.