basic search procedure 1. start with the start node (root of the search tree) and place in on the...
TRANSCRIPT
Basic Search ProcedureBasic Search Procedure
1. Start with the start node (root of the search 1. Start with the start node (root of the search tree) and place in on the tree) and place in on the queuequeue
2. Remove the front node in the queue and 2. Remove the front node in the queue and If the node is a If the node is a goal nodegoal node, then we are done; stop., then we are done; stop. Otherwise Otherwise expandexpand the node the node generate its children generate its children
using the successor function (other states that can be using the successor function (other states that can be reached with one move)reached with one move)
3. Place the children on the queue according to 3. Place the children on the queue according to the the search strategysearch strategy
4. Go back to step 2.4. Go back to step 2.
Search StrategiesSearch Strategies
Search strategies differ based on the order Search strategies differ based on the order in which new successor nodes are added in which new successor nodes are added to the queueto the queueBreadth-first Breadth-first add nodes to the end of add nodes to the end of the queuethe queueDepth-first Depth-first add nodes to the front add nodes to the frontUniform cost Uniform cost sort the nodes on the sort the nodes on the queue based on the cost of reaching the queue based on the cost of reaching the node from start nodenode from start node
Breadth-First SearchBreadth-First Search
add nodes to the end of the queueadd nodes to the end of the queue
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
A
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
B I E
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
I E C D
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
E C D M K
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
C D M K F H
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
D M K F H N
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
M K F H N
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
K F H N O G
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
F H N O G
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
H N O G Q
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
N O G Q R T
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
O G Q R T P S
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
G Q R T P S
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
Q R T P S
DONE!!!
Solution: A I M G
Depth-First SearchDepth-First Search
add nodes to the front of the queueadd nodes to the front of the queue
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
A
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
B I E
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
C D I E
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
N D I E
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
P S D I E
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
S D I E
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
D I E
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
I E
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
M K E
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
O G K E
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
G K E
Breadth-First SearchBreadth-First SearchA
IB E
C D M K
N
F H
O G Q R T
P S
goal
Queue:
K E
DONE!!!
Solution: A I M G
Example: The 8-PuzzleExample: The 8-Puzzle
States?States? integer location of tilesinteger location of tiles
Operators? Operators? move blank left, right, up, downmove blank left, right, up, down
Goal Test?Goal Test? = goal state (given)= goal state (given)
Path Cost?Path Cost? One per moveOne per move
We will assume that we can do repeated state checking(i.e., we will not generate nodes that have been previously expanded)
5 4
6 1 8
7 3 2
Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search
5 4
6 1 8
7 3 2
5 4
6 1 8
7 3 2
5 4 8
6 1
7 3 2
Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search
5 4
6 1 8
7 3 2
5 4
6 1 8
7 3 2
5 4 8
6 1
7 3 2
5 4
6 1 8
7 3 2
5 1 4
6 8
7 3 2
Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search
5 4
6 1 8
7 3 2
5 4
6 1 8
7 3 2
5 4 8
6 1
7 3 2
5 4
6 1 8
7 3 2
5 1 4
6 8
7 3 2
6 5 4
1 8
7 3 2
Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search
5 4
6 1 8
7 3 2
5 4
6 1 8
7 3 2
5 4 8
6 1
7 3 2
5 4
6 1 8
7 3 2
5 1 4
6 8
7 3 2
6 5 4
1 8
7 3 2
6 5 4
1 8
7 3 2
6 5 4
7 1 8
3 2
Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search
5 4
6 1 8
7 3 2
5 4
6 1 8
7 3 2
5 4 8
6 1
7 3 2
5 4
6 1 8
7 3 2
5 1 4
6 8
7 3 2
6 5 4
1 8
7 3 2
5 1 4
6 8
7 3 2
5 1 4
6 8
7 3 2
5 1 4
6 3 8
7 2
6 5 4
1 8
7 3 2
6 5 4
7 1 8
3 2
Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search
5 4
6 1 8
7 3 2
5 4
6 1 8
7 3 2
5 4 8
6 1
7 3 2
5 4
6 1 8
7 3 2
5 1 4
6 8
7 3 2
6 5 4
1 8
7 3 2
5 1 4
6 8
7 3 2
5 1 4
6 8
7 3 2
5 1 4
6 3 8
7 2
6 5 4
1 8
7 3 2
6 5 4
7 1 8
3 2
1 4
5 6 8
7 3 2
5 1 4
7 6 8
3 2
Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search
5 4
6 1 8
7 3 2
5 4
6 1 8
7 3 2
5 4 8
6 1
7 3 2
5 4
6 1 8
7 3 2
5 1 4
6 8
7 3 2
5 4 8
6 1
7 3 2
5 4 8
6 1 2
7 3
6 5 4
1 8
7 3 2
5 1 4
6 8
7 3 2
5 1 4
6 8
7 3 2
5 1 4
6 3 8
7 2
5 8
6 4 1
7 3 2
5 4 8
6 3 1
7 2
5 4 8
6 1
7 3 2
5 4 8
6 1 2
7 3
6 5 4
1 8
7 3 2
6 5 4
7 1 8
3 2
1 4
5 6 8
7 3 2
5 1 4
7 6 8
3 2 . . .
Example: 8-Puzzle – Depth First SearchExample: 8-Puzzle – Depth First Search