Solving Problems by Searching
Solving Problems by Searching
Solving Problems by Searching
Searching
Terminology
State
State Space
Goal
Action
Cost
State Change Function
Problem-Solving Agent
State-Space Search
2
f: S x A -> S
g: S -> {true,false}
c: S x A x S -> R
3 Coins Problem
A Very Small State Space Problem
There are 3 (distinct) coins: coin1, coin2, coin3.
The initial state is
What are S, s, A, f, g, c ?
H
T
H
T
H
T
State-Space Graph
2
HHT
THT
3
HTT
3
THH
1
HHH
TTT
3
HTH
TTH
1
What are some solutions?
What if the problem is changed to allow only 3 actions?
7 2 4
5 B 6
8 3 1
B 1 2
goal 3 4 5
state 6 7 8
B=blank
Q
Q
Q
Start state
Goal state (test)
Output
10
Search Strategies
Blind Search (Ch 3)
Time Complexity?
O(b^d)
Space ?
O(d)
e
d
13
Yes
Time Complexity?
O(b^d)
Space?
O(b^d)
14
15
16
Left Bank
Right Bank
River
17
19
Assignment
Implement and solve the problem with a depthfirst search using a stack and/or recursion.
Find and print all 4 solutions. (See web page.)
Keep track of the total number of states searched.
When you get to a dead state, count it and then back
up to its parent.
Is memory a limitation in
search?
Suppose:
2 GHz CPU
1 GB main memory
100 instructions / expansion
5 bytes / node
Complete?
Yes
c f
d i
Time Complexity?
O(b^d)
Space Complexity?
O(d)
22
ratio ID to DFS
1.5
10
1.2
25
1.08
100
1.02
23
sta
rt
24
vs. Bidirectional
25
Problem
All these methods are too slow for real
applications (blind)
Solution
add guidance
informed search
26