0% found this document useful (0 votes)
10 views37 pages

vR21-CS34O1 ALGORITHMS Unit-IV

Uploaded by

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

vR21-CS34O1 ALGORITHMS Unit-IV

Uploaded by

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

State Space

Search
Algorithms
Root node
Depth First
1
Search
6 7
E node b Problem
2 states
8
4 5
3 9 10

Solution
states

Dead Live node Answer


node state
Applications

 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

 S ={S1 ,…….Sn },d=


Set of ‘N’ positive integers
 S1 <S
_ 2<…<S
_ n

Sort into ascending


Sum is equal to given positive integer ‘d’
Given S={3,5,6,7}, d=15
:
Graph colouring problem
Undirected Graph
M different colours
No two adjacent vertices in same
colour
Node 0 -> color
1 Blue

Node 1 -> color Green


2 Red
Node 2 -> color Green
3
Node 3-> color 2

4 node graph and all possible 3-


colouring
To Applied
Not necessary Breadth
To use Depth First Search
First Search

To Avoid generating

Of subtrees that do not


Contain answer node
Applications
Solving 15-Puzzle Problem
Assignment Problem
Knapsack Problem
Travelling Salesman
Problem
Solving 15-Puzzle Problem

Initial Arrangement Goal Arrangement


Any 4 moves possible once at a time-left,
right ,up ,down
Each and Every moves create a new arrangement
C(x)=f(x)+g(x) , C(x)< Infinity
 f(x) is length of path from root to node x
g(x) is Number of non blank tile not in their correct
position
State Space tree with node cost is show
Assignment Problem

 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

Upper bound formula:


Knapsack Capacity ,W=10

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:

You might also like