Breadth First Search
Breadth First Search
Step 1: Initially NODE-LIST contains only one node corresponding to the source state A.
A
B
C
D
E
D
G
C
F
B
F
G
H
G
H
G
E
A
Node-List:
Breadth First Search
Step 2: A is removed from NODE-LIST. The node is expanded, and its children B
and C are generated. They are placed at the back of NODE-LIST.
A
B
C
D
E
D
G
C
F
B
F
G
H
G
H
G
E
BC
Node-List:
Breadth First Search
Step 3: Node B is removed from NODE-LIST and is expanded. Its children D, E are
generated and put at the back of NODE-LIST.
A
B
C
D
E
D
G
C
F
B
F
G
H
G
H
G
E
CDE
Node-List:
Breadth First Search
Step 4: Node C is removed from NODE-LIST and is expanded. Its children D and
G are added to the back of NODE-LIST.
A
B
C
D
E
D
G
C
F
B
F
G
H
G
H
G
E
DEDG
Node-List:
Breadth First Search
Step 5: Node D is removed from NODE-LIST. Its children C and F are generated
and added to the back of NODE-LIST.
A
B
C
D
E
D
G
C
F
B
F
G
H
G
H
G
E
EDGCF
Node-List:
Breadth First Search
Step 6: Node E is removed from NODE-LIST. It has no children.
A
B
C
D
E
D
G
C
F
B
F
G
H
G
H
G
E
DGCF
Node-List:
Breadth First Search
Step 7: D is expanded; B and F are put in OPEN.
A
B
C
D
E
D
G
C
F
B
F
G
H
G
H
G
E
GCFBF
Node-List:
Breadth First Search
Step 8: G is selected for expansion. It is found to be a goal node.
Hence the algorithm returns the path A - C - G by following the parent pointers of the node corresponding to G.
A
B
C
D
E
D
G
C
F
B
F
G
H
G
H
G
E
Goal Reached!!
Breadth First Search
Advantages of Breadth first search are:
Disadvantages of Breadth first search are :
Depth First Search
Depth First Search
Step 1: Initially NODE-LIST contains only one node corresponding to the source state A.
A
B
C
D
E
D
G
C
F
B
F
G
H
G
H
G
E
A
Node-List:
Depth First Search
Step 2: A is removed from NODE-LIST. A is expanded, and its children B
and C are inserted at the front of NODE-LIST.
A
B
C
D
E
D
G
C
F
B
F
G
H
G
H
G
E
BC
Node-List:
Depth First Search
Step 3: Node B is removed from NODE-LIST and its children D and E are pushed in front of NODE-LIST.
A
B
C
D
E
D
G
C
F
B
F
G
H
G
H
G
E
DEC
Node-List:
Depth First Search
Step 4: Node D is removed from NODE-LIST and its children C and F are pushed in front of NODE-LIST.
A
B
C
D
E
D
G
C
F
B
F
G
H
G
H
G
E
CFEC
Node-List:
Depth First Search
Step 5: Node C is removed from NODE-LIST and its children G is pushed in front of NODE-LIST.
A
B
C
D
E
D
G
C
F
B
F
G
H
G
H
G
E
GFEC
Node-List:
Depth First Search
Step 6: Node G is expanded and found to be a goal.
Hence the algorithm returns the path A – B – D - C - G and terminates.
A
B
C
D
E
D
G
C
F
B
F
G
H
G
H
G
E
GFEC
Node-List:
Goal Reached!!
Depth First Search
Advantages of Depth-first search are:
Disadvantages of Depth-first search are: