UNIT 4 - CS3401-Algorithms
UNIT 4 - CS3401-Algorithms
In state space tree, nodes are numbered as per the level. In each
level, we must calculate the cost of each node by using given
formula:
Initial State
ĉ(2) = 1+4 = 5 less(1) = 0, less(2) = 0, less(3) = 0, less(4) = 0, less(5) = 0,
ĉ(3) = 1+2 = 3 less(6) = 0, less(7) = 0, less(8) = 0, less(9) = 0, less(10) = 0,
ĉ(4) = 1+4 = 5 less(11) = 0, less(12) = 0, less(13) = 0, less(14) = 0, less(15) = 0
ĉ(5) = 1+4 = 5
Since ĉ (3) is the lowest value, next E-node is node 3. r = 4 (row number of Empty Spot (ES))
∑ (0+0+0+0+0+0+0+0+0+0+0+0+0+0+0) + 4 = 4
ĉ(8) = 2+3 = 5
ĉ(9) = 2+1 = 3 Goal State
ĉ(10) = 2+3 = 5 less(1) = 0, less(2) = 0, less(3) = 0, less(4) = 0, less(5) = 0,
less(6) = 0, less(7) = 0, less(8) = 0, less(9) = 0, less(10) = 0,
Since ĉ (9) is the lowest value, next E-node is node 9. less(11) = 0, less(12) = 0, less(13) = 0, less(15) = 1, less(14) = 0
ĉ(19) = 3+2 = 5
ĉ(20) = 3+0 = 3 r = 4 (row number of Empty Spot (ES))
∑ (0+0+0+0+0+0+0+0+0+0+0+0+0+1+0) + 4 = 5
Next E-node is node 20, which is the answer node.
Since the initial and the goal state are of different parity the goal
state is not reachable from the initial state.
Since the initial and the goal state are same parity (even), the goal
state is reachable from the initial state.
Solution
Computation at Node III Computation at Node IV Thus solution is pick up (item1, item3) and
With item2 Without item2 gain maximum profit = $40+$25 = $65
i=2 i=2 State Space Tree
w=4+7=11, W=10 w=4, v=40, W=10
This exceed the capacity of vi+1/wi+1 = v3/w3=5
knapsack. It is not feasible. ub= v + (W-w) (vi+1/wi+1)
= 40 + (10-4) (5)
ub= $ 70
Note: This is the solution for knapsack because the weight of selected items
(w=15) is equal to capacity (W=15) for knapsack.
Solution:
Hence the optimum cost tour of TSP is a-b-c-e-d-a with cost 17.
CS3401-ALGORITHMS (Sem-IV-R2021) - UNIT-IV: 10
Example 2: Apply Branch and Bound Algorithm to solve the State Space Tree
Traveling Salesman Problem
Solution
Calculate Lower Bound(LB)
a->ab+ac=2+5=7
b->ba+bd=2+3=5
c->cd+ca=1+5=6
d->dc+db=1+3=4
lb=(7+5+6+4)/4=22/2=11
lb=11
Hence the optimum cost tour of TSP is a-b-d-c-a with cost 11.
CS3401-ALGORITHMS (Sem-IV-R2021) - UNIT-IV: 11
1) What is Backtracking? 4) State Hamiltonian Circuit (Cycle) problem.
Backtracking is an algorithm that finds all the possible Hamiltonian Cycle or Circuit is a path in an undirected graph
solutions and selects the desired solution from the given set of that visits all the vertices in the graph exactly once and returns
solutions. to the starting vertex.
When to Use a Backtracking Algorithm?
Problem Statement: Given an undirected graph, our task is to
There are multiple possible solutions to the problem.
The problem can be broken down into smaller sub- determine whether the graph contains a Hamiltonian cycle or
problems. not.
The sub-problems can be solved independently.