Chapter 3 - Searching Algorithm
Chapter 3 - Searching Algorithm
3
4
transition model
a description of what state results from
performing any applicable action in any
state
transition model
RESULT(s, a) returns the state resulting from
performing action a in state s
2 4 5 7 2 4 5 7
8 3 1 11 8 3 1 11
RESULT( , )=
14 6 10 12 14 6 10 12
9 13 15 9 13 15
2 4 5 7 2 4 5 7
8 3 1 11 8 3 1 11
RESULT( , )=
14 6 10 12 14 6 10
9 13 15 9 13 15 12
transition model
2 4 5 7 2 4 5 7
8 3 1 11 8 3 1 11
RESULT( , )=
14 6 10 12 14 6 10
9 13 15 9 13 15 12
state space
the set of all states reachable from the
initial state by any sequence of actions
goal test
way to determine whether a given state
is a goal state
path cost
numerical cost associated with a given path
A
B
C D
E F G
I K
H J
L
M
A 4
2 B
5 2
1
C D 6
E F G
3 2 3
I 4 K 3
H 4 J 2
1
2 L
M
A 1
1 B
1 1
1
C D 1
E F G
1 1 1
I 1 K 1
H 1 J 1
1
1 L
M
Search Problems
• initial state
• actions
• transition model
• goal test
• path cost function
solution
a sequence of actions that leads from the
initial state to a goal state
optimal solution
a solution that has the lowest path cost
among all solutions
node
a data structure that keeps track of
- a state
- a parent (node that generated this node)
- an action (action applied to parent to get node)
- a path cost (from initial state to node)
Approach
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
E D
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
Find a path from A to E. A
B
Frontier
C D
• Start with a frontier that contains the initial state.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier. E
• If node contains goal state, return the solution. F
• Expand node, add resulting nodes to the frontier.
What could go wrong?
Find a path from A to E. A
B
Frontier
C D
E
F
Find a path from A to E. A
B
Frontier
C D
E
F
Find a path from A to E. A
B
Frontier
C D
E
F
Find a path from A to E. A
B
Frontier
C D
E
F
Find a path from A to E. A
B
Frontier
C D
E
F
Find a path from A to E. A
B
Frontier
A C D
C D
E
F
Find a path from A to E. A
B
Frontier
C D
C D
E
F
Revised Approach
• Start with a frontier that contains the initial state.
• Start with an empty explored set.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier.
• If node contains goal state, return the solution.
• A d d the node to the explored set.
• Expand node, add resulting nodes to the frontier if they
aren't already in the frontier or the explored set.
Revised Approach
• Start with a frontier that contains the initial state.
• Start with an empty explored set.
• Repeat:
• If the frontier is empty, then no solution.
• Remove a node from the frontier.
• If node contains goal state, return the solution.
• A d d the node to the explored set.
• Expand node, add resulting nodes to the frontier if they
aren't already in the frontier or the explored set.
stack
last-in first-out data type
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A B
E
F
Find a path from A to E. A
B
Frontier
C D
C D
Explored Set
A B
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A B D
E
F
Find a path from A to E. A
B
Frontier
C F
C D
Explored Set
A B D
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A B D F
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A B D F C
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A B D F C
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A B D F C
E
F
Depth-First Search
depth-first search
search algorithm that always expands the
deepest node in the frontier
Breadth-First Search
breadth-first search
search algorithm that always expands the
shallowest node in the frontier
queue
first-in first-out data type
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A B
E
F
Find a path from A to E. A
B
Frontier
C D
C D
Explored Set
A B
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A B C
E
F
Find a path from A to E. A
B
Frontier
D E
C D
Explored Set
A B C
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A B C D
E
F
Find a path from A to E. A
B
Frontier
E F
C D
Explored Set
A B C D
E
F
Find a path from A to E. A
B
Frontier
C D
Explored Set
A B C D
E
F
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Depth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
Breadth-First Search
A
uninformed search
search strategy that uses no problem-
specific knowledge
informed search
search strategy that uses problem-specific
knowledge to find solutions more efficiently
greedy best-first search
search algorithm that expands the node
that is closest to the goal, as estimated by a
heuristic function h(n)
Heuristic function?
A
Heuristic function?
A
Heuristic function? Manhattan distance.
A
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
11 9 7 3 2 B
12 10 8 7 6 4 1
13 12 11 9 7 6 5 2
13 10 8 6 3
14 13 12 11 9 7 6 5 4
13 10
A 16 15 14 11 10 9 8 7 6
Greedy Best-First Search
10 9 8 7 6 5 4 3 2 1 B
11 1
12 10 9 8 7 6 5 4 2
13 11 5 3
14 13 12 10 9 8 7 6 4
13 11 5
A 16 15 14 12 11 10 9 8 7 6
Greedy Best-First Search
10 9 8 7 6 5 4 3 2 1 B
11 1
12 10 9 8 7 6 5 4 2
13 11 5 3
14 13 12 10 9 8 7 6 4
13 11 5
A 16 15 14 12 11 10 9 8 7 6
Greedy Best-First Search
10 9 8 7 6 5 4 3 2 1 B
11 1
12 10 9 8 7 6 5 4 2
13 11 5 3
14 13 12 10 9 8 7 6 4
13 11 5
A 16 15 14 12 11 10 9 8 7 6
A* search
search algorithm that expands node with
lowest value of g(n) + h(n)
10 9 8 7 6 5 4 3 2 1 B
11 1
12 10 9 8 7 6 5 4 2
13 11 5 3
14 13 12 10 9 8 7 6 4
13 11 5
A 16 15 14 12 11 10 9 8 7 6
A* Search
10 9 8 7 6 5 4 3 2 1 B
11 1
12 10 9 8 7 6 5 4 2
13 11 5 3
14 13 12 10 9 8 7 6 4
13 11 5
A 1+16 15 14 12 11 10 9 8 7 6
A* Search
10 9 8 7 6 5 4 3 2 1 B
11 1
12 10 9 8 7 6 5 4 2
13 11 5 3
14 13 12 10 9 8 7 6 4
13 11 5
A 1+16 2+15 14 12 11 10 9 8 7 6
A* Search
10 9 8 7 6 5 4 3 2 1 B
11 1
12 10 9 8 7 6 5 4 2
13 11 5 3
14 13 12 10 9 8 7 6 4
13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
12 10 9 8 7 6 5 4 2
13 11 5 3
14 13 12 10 9 8 7 6 4
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
12 10 9 8 7 6 5 4 2
13 11 5 3
14 13 5+12 10 9 8 7 6 4
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
12 10 9 8 7 6 5 4 2
13 6+11 5 3
14 13 5+12 10 9 8 7 6 4
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
12 7+10 9 8 7 6 5 4 2
13 6+11 5 3
14 13 5+12 10 9 8 7 6 4
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
12 7+10 8+9 8 7 6 5 4 2
13 6+11 5 3
14 13 5+12 10 9 8 7 6 4
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
13 6+11 5 3
14 13 5+12 10 9 8 7 6 4
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
13 6+11 5 3
14 13 5+12 10 9 8 7 6 4
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
13 6+11 5 3
14 13 5+12 10 9 8 7 6 4
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
13 6+11 5 3
14 13 5+12 10 9 8 7 6 4
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
13 6+11 5 3
14 13 5+12 10 9 8 7 6 4
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
13 6+11 14+5 3
14 13 5+12 10 9 8 7 6 4
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
13 6+11 14+5 3
14 6+13 5+12 10 9 8 7 6 4
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
13 6+11 14+5 3
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
13 6+11 14+5 3
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
11 1
4+13 11 5
10 9 8 7 6 5 4 3 2 1 B
10+11 1
4+13 11 5
11+10 9 8 7 6 5 4 3 2 1 B
10+11 1
4+13 11 5
11+10 12+9 8 7 6 5 4 3 2 1 B
10+11 1
4+13 11 5
4+13 11 5
4+13 11 5
4+13 11 5
4+13 11 5
4+13 11 5
4+13 11 5
4+13 11 5
11+10 12+9 13+8 14+7 15+6 16+5 17+4 18+3 19+2 20+1 B
10+11 1
4+13 11 5