Professional Documents
Culture Documents
Uninformed Search
Type of problems
• Games – Chess, Tic-Tac-Toe, 8-Queen etc.
• Real World Problems – Route Finding,
Travelling Salesman Problem, Robot
Navigation etc.
• Pattern Recognition – Face Recognition,
Clustering, Feature Selection etc.
State :3
State 4
State :0
State 5
(0,0) (0,12)
else
x=x+10; (10,12)
• <x1,x2,x3,x4,x5,x6,x7,x8 x4 x5 x6
x7 x8 x9
,x9>
• Start state
<7,2,4,5,-1,6,8,3,1>
• Goal State
<-1, 1, 2, 3, 4, 5, 6, 7, 8>
1 2 3 1 2 3
7 5 4 5 6
8 4 6 7 8
Left Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
7 5 7 5 7 2 5 7 4 5
8 4 6 8 4 6 8 4 6 8 6
Each possible action (such as move the Left key to the empty place)
takes the Goal agent to a different state
Left
Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
7 5 7 5 7 2 5 7 4 5
8 4 6 8 4 6 8 4 6 8 6
Left Right up
Right Down
Up
1 2 3 2 3 1 2 3
4 5 1 4 5 7 4 5
7 8 6 7 8 6 8 6
Left Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
7 5 7 5 7 2 5 7 4 5
8 4 6 8 4 6 8 4 6 8 6
Left Right up
1 2 33 1 2 3 1 2 3
7 4 55 7 4 5 7 5
8 66 8 6 8 4 6
Right
Up
1 2 3 1 2 3
7 4 5 4 5
8 6 7 8 6
Right Up Down
11 2 33 2 3 1 2 3
44 55 1 4 5 7 4 5
77 8 66 7 8 6 8 6
Left Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
4 5 4 5 4 2 5 4 8 5
7 8 6 7 8 6 7 8 6 7 6
Left Up Down
1 2 3 1 2 1 2 3
4 5 4 5 3 4 5 6
7 8 6 7 8 6 7 BITS
Partially constructed
8 Pilani, BITS F444/ CS
Search tree
Vandana,
August 2016 16
F407
Search Tree Construction
Complexity of the search space tree
• At level 0 : Maximum number of nodes = 1
• At level 1: Maximum number of nodes = 4
• At level 2: Maximum number of nodes = 42
• At level 3: Maximum number of nodes = 43
• At level 4: Maximum number of nodes = 44
• …….
• At level d: Maximum number of nodes = 4d
A better definition
typedef struct
{
state s;
boolean explored;
depth d;
action A; //to reach the state s at depth
} lookupTable[maxStates];
This table can be populated and propagated
down with every action along the branch of the
tree and a state is reached if it was not earlier.
Vandana, BITS Pilani, BITS F444/ CS
August 2016 19
F407
State (All possible explored depth action
states)
1,2,3,7,-1,5,8,4,6 NO 0 0
1,2,3,7,4,5,8,-1,6 NO 0 0
…..
Initial Table
Vandana, BITS Pilani, BITS F444/ CS
August 2016 20
F407
1 2 3
Search Tree Construction 7 5
Initial State
8 4 6
Left Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
7 5 7 5 7 2 5 7 4 5
8 4 6 8 4 6 8 4 6 8 6
Left Right up
1 2 33 1 2 3 1 2 3
7 4 55 7 4 5 7 5
8 66 8 6 8 4 6
Need to handle Right
Up
1 2 3 1 2 3
repeated state 7 4 5 4 5
8 6 7 8 6
Right Up Down
11 2 33 2 3 1 2 3
44 55 1 4 5 7 4 5
77 8 66 7 8 6 8 6
Left Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
4 5 4 5 4 2 5 4 8 5
7 8 6 7 8 6 7 8 6 7 6
Left Up Down
1 2 3 1 2 1 2 3
4 5 4 5 3 4 5 6
7 8 6 7 8 6 7 BITS
8 Pilani, BITS F444/ CS
Vandana,
August 2016 21
F407
State (All possible explored depth action
states)
1,2,3,7,-1,5,8,4,6 YES 0 0
NO
YES …..
Table
Vandana, BITS Pilani, BITS F444/ CS
August 2016 22
F407
Use of appropriate data
1 2 3
structure and a suitable 7 5
Initial State
algorithm can avoid 8 4 6
expanding the node
Left
unnecessarily Right Up
Down
1 2 3 1 2 3 1 3 1 2 3
7 5 7 5 7 2 5 7 4 5
8 4 6 8 4 6 8 4 6 8 6
Left Right up
1 2 33 1 2 3 1 2 3
7 4 55 7 4 5 7 5
8 66 8 6 8 4 6
Right
Up
1 2 3 1 2 3
7 4 5 4 5
8 6 7 8 6
Right Up Down
11 2 33 2 3 1 2 3
44 55 1 4 5 7 4 5
77 8 66 7 8 6 8 6
Left Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
4 5 4 5 4 2 5 4 8 5 Same states
7 8 6 7 8 6 7 8 6 7 6
Left Up Down
1 2 3 1 2 1 2 3
4 5 4 5 3 4 5 6
7 8 6 7 8 6 7 BITS
8 Pilani, BITS F444/ CS
Vandana,
August 2016 23
F407
Redefine a Node structure
struct node
{
state s;
lookupTable T;
struct node *left;
struct node *right;
struct node *up;
struct node *down;
}
Left Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
7 5 7 5 7 2 5 7 4 5
8 4 6 8 4 6 8 4 6 8 6
Left Right up
1 2 33 1 2 3 1 2 3
7 4 55 7 4 5 7 5
8 66 8 6 8 4 6
Right
Up
1 2 3 1 2 3
7 4 5 4 5
8 6 7 8 6
Right Up Down
11 2 33 2 3 1 2 3
44 55 1 4 5 7 4 5
77 8 66 7 8 6 8 6
Left Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
4 5 4 5 4 2 5 4 8 5
7 8 6 7 8 6 7 8 6 7 6
Left Up Down
1 2 3 1 2 1 2 3
4 5 4 5 3 4 5 6
7 8 6 7 8 6 7 BITS
8 Pilani, BITS F444/ CS
Vandana,
August 2016 25
F407
A node and its size
Left Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
7 5 7 5 7 2 5 7 4 5
8 4 6 8 4 6 8 4 6 8 6
Left Right up
Recall: 1 2 33 1 2 3 1 2 3
4 55 7 4 5 7 5
1. State 7
8 66 8 6 8 4 6
2. Action Right
Up
3. Goal Test 1 2 3 1 2 3
7 4 5 4 5
4. Path cost 8 6 7 8 6
Right Up Down
11 2 33 2 3 1 2 3
44 55 1 4 5 7 4 5
77 8 66 7 8 6 8 6
Left Down
Right Up
1 2 3 1 2 3 1 3 1 2 3
4 5 4 5 4 2 5 4 8 5 Same states
7 8 6 7 8 6 7 8 6 7 6
Left Up Down
1 2 3 1 2 1 2 3
4 5 4 5 3 4 5 6
7 8 6 7 8 6 7 BITS
8 Pilani, BITS F444/ CS
Vandana,
August 2016 29
F407
Tree Data Structure
• What is a Data Structure?
• Why is memory required?
• What are different logical segments of
memory?
• Use of malloc() function in C
• What is a tree data structure?
• What is its actual layout in the memory?
• How is tree different from linked list?
Goal
Tree is expanded to depth = 2
State
Number of nodes = O(bd+1)
• The root node is expanded first and then all its children
are expanded.
• The nodes at the next level are expanded only after all
the nodes in the previous level are expanded.
Root node
stack
stack
node2 node 2
node1
If node2 is goal Root node
state, terminate
search
stack
node2 node 2
node1
Root node
stack
Node 3
node2 node 2
node1
Root node
stack
node3
Vandana, BITS Pilani, BITS F444/ CS
August 2016 48
F407
Memory requirement
• It requires very less memory
• It maintains nodes only in one path.
• The maximum size of the stack determines the
total memory requirements for DFS.
• A node whose all children are expanded and
explored fully then the node address is popped
off from the top of the stack. Now its next sibling
gets expanded.
• For a depth ‘d’, the only requirement is of ‘d’
nodes to be preserved along the path/branch.
BFS DFS
Space O(bd+1) O(bm)
time O(bd+1) O(bm)
Complete? Yes No
Optimal? Yes No
Node 1
Node 2
Node 2 does not expand at this
iteration as already level two is
reached.