Depth-First Searches G5AIAI – Introduction to AI Depth-First Search • Depth first search explores one branch of a tree before it starts to.

Download Report

Transcript Depth-First Searches G5AIAI – Introduction to AI Depth-First Search • Depth first search explores one branch of a tree before it starts to.

Depth-First Searches
G5AIAI – Introduction to AI
Depth-First Search
• Depth first search explores one branch of a tree before it
starts to explore another branch. It can be implemented by
adding newly expanded nodes at the front of the queue.
• Using the general search algorithm we can implement it as
follows:
Function DEPTH-FIRST-SEARCH(problem) returns a solution or failure
Return GENERAL-SEARCH(problem,ENQUEUE-AT-FRONT)
• The following slide illustrates a depth-first search of 26
nodes (states) with an initial state of node A and a goal
state of node L. Press space to see the example node set.
The example node set
Initial state
A
B
C
D
E
F
Goal state
G H
I
J
K
L
M N
O
P
Q
S
T
U V
W X
Y
Z
R
Press space to see a DFS of the example node set
The process
Node
search
B is expanded
then
nowmoves
continues
andtoremoved
the
until
first
the
from
node
in the
the
goal
queue.
state
queue.
isRevealed
achieved.
Press space
nodes
Press
toare
continue
space.
added to
the FRONT of the queue. Press space.
B
A
C
D
G H
I
J
K
Q
S
T
U
R
Node
We
This
begin
node
A is with
removed
is then
ourexpanded
initial
from the
state:
to
queue.
reveal
the node
Each
labeled A.
further
revealed
(unexpanded)
node
Press
is space
addednodes.
totocontinue
the Press
FRONT
space.
of
the queue. Press space to continue.
E
L
F
Node L is located and the search
returns a solution. Press space to
end.
Press space to continue
begin thethe
search
search
Size of Queue: 034561
Queue: A
T,
B,J,
G,
Q,
H,
R,
C,
I,
S,
J,
D,
K,
U,
L,
Empty
D,
J,
C,
E,
D,
L,
H,D,
C,
D,
E,
F
E,
D,
D,
C,E,
E,
FF
E,
E,
D,FFF
F
E, F
Nodes expanded: 14
9876543210
10
11
12
13
CurrentFINISHED
Action: Backtracking
Expanding
SEARCH
DEPTH-FIRST SEARCH PATTERN
Current level: 2130n/a