2. Search Algorithms
2. Search Algorithms
3
Define a problem
Problem: 8 - Puzzle
4
Define a problem
Problem: 8 - Puzzle
How many states 8-puzzle has?
9!/2 = 181,440 states
7
Define a problem as a search
problem
Search problem’s components:
• Initial state
• State space S
• Successor function:
x ∈ S → SUCCESSORS(x) ∈ 2S
• Goal test: x ∈ S → GOAL?(x) =T or F
• Arc Cost
8
State Graph
10
#1 #2 #3
Problem formulation
#1 #2 #3
11
State space
13
Search Algorithms
14
a G
b c
Blind search e
d f
Breath First Search S h
Strategy: expand a shallowest p r
q
node first
S
d e p
Search
b c e h r q
Tiers
15
a a h r p q f
p q f q c G
q c a
G
a
Blind search
Breath First Search
Strategy: expand a shallowest node first
Visited
S
Queue
1 2
First Last
Visited
S 1
Queue
2 3
First Last
Visited
S 1 2
Queue
3 4
First Last
Visited
S 1 2
Queue
4 5
First Last
Visited
S 1 2 3 4
Queue
5
First Last
Visited
S 1 2 3 4 5
Queue
Shortest Path
S 2 3 5
Blind search
Breath First Search
Strategy: expand a shallowest node first
Blind search
Breath First Search
Strategy: expand a shallowest node first
d e p
b c e h r q
a a h r p q f
p q f q c G
q c a
G
a
2 a G
b 8 c
Blind search 1
2 2
3 e
d 9 2 f
Uniform Cost Search S h 8
1
Strategy: expand a cheapest node first: 1 p r
q
15
S 0
d 3 e 9 p 1
b 4 c e 5 h 17 r 11 q 16
11
25
a 6 a h 13 r 7 p q f
Cost
contours q c
p q f 8 G
q c a
11 G 10
a
Heuristic search
h(x) 27
Heuristic search
Greedy Search
28
Heuristic search
Greedy Search
10
5
11.2
29
Heuristic search
A* Search : find the shortest path by combine heuristic cost and cost to
reach node n from start state
30
Heuristic search
A* Search : find the shortest path by combine heuristic cost and cost to
reach node n from start state
http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html 31
Heuristic search
Greedy
A*
Uniform Cost
32
Heuristic search
A* Search
33