vR21-CS34O1 ALGORITHMS Unit-IV
vR21-CS34O1 ALGORITHMS Unit-IV
Search
Algorithms
Root node
Depth First
1
Search
6 7
E node b Problem
2 states
8
4 5
3 9 10
Solution
states
N –Queens Problem
Hamiltonian Circuit Problem
Subset sum problem
Graph Colouring Problem
Two types of constraints
Type1 • Explicit
constraint
Type2
• Implicit
constraint
N Queens Problem
N queen problem
N x N chess board
No two queens attack -same rows, columns, diagonals
N=1 is trivial, N=2,3 are no solution, Let N=4
4 queens solution space in DFS:
The Solution is
(3,2,4,2)
8 Queens
Problem:
Hamiltonian Circuit Problem
Undirected Graph
Visits each vertex exactly once
Returns to the starting vertex
SUBSET SUM PROBLEM
To Avoid generating
N –Persons
N –rows
N x N –matrix
Find the total cost of assignments in
smallest possible
No two selected elements –same column
Their sum is smallest as far as possible
To find the Lower Bound(LB),select the minimum costs from each rows
The solution is , person a = job 2
person b = job 1
person c = job 3
person d = job 4
Knapsack problem
Contains ‘N’ objects or items
Each item has a weight - i w
Knapsack has a capacity - W
Profit is earned- j v
Descending order of value to weight
ratio
Solution:
The solution is pickup{item 1, item 3} and gain maximum profit
65$
Travelling Salesman Problem
oN cities
oCost of travelling from any city to another
city
oEach city is visited exactly once
oReturning to starting city
oLower Bound Formula: