Professional Documents
Culture Documents
Ai 04
Ai 04
Ai 04
04
Dr. Eng. Yasser KHADRA
Associate Professor
• On holiday in Damascus;
currently in Latakia.
• Formulate goal: be in
Damascus
• Formulate problem:
• states: various cities
• actions: drive between
cities
• Find solution:
• sequence of cities, e.g.,
Latakia, Tartus, Homes,
Damascus
• The algorithm efficiently visits and marks all the key nodes in a
graph in an accurate breadthwise fashion.
pop
FIFO
current
a
a b c
b c d e
c d e f g
d e f g
e f g
f g
g
A B C D
B C D G H
C D G H E F
D G H E F
G H E F I
H E F I
E F I K
F I K
I K
S→A→B→C→ D→G →H→ E→ F→I→K K
pop
FIFO Goal
Start
Skip because It is
Output: [S → D → G] already visited (D)
LIFO
Output: A D G C B F E
Start
pop
LIFO
➢ Advantage:
➢ DFS requires very less memory as it only needs to store a stack of the
nodes on the path from root node to the current node.
➢ It takes less time to reach to the goal node than BFS algorithm (if it
traverses in the right path).
➢ Disadvantage:
➢ There is the possibility that many states keep re-occurring, and there is
no guarantee of finding the solution.
➢ DFS algorithm goes for deep down searching and sometime it may go to
the infinite loop.