AI Lecture 3
AI Lecture 3
S --> A --> B --> C--> D --> G --> H --> E --> F --> I --> K
Breadth-first search (BFS)
Example 2: Consider 1 be the start state and 7 be the goal
state. Apply BFS to show expanded nodes for each step.
2 3
4 5 6 7
8 9
Breadth-first search (BFS)
2 3 FRINGE = (1)
4 5 6 7
8 9
Breadth-First Strategy
2 3 FRINGE = (2, 3)
4 5 6 7
8 9
Breadth-First Strategy
2 3 FRINGE = (3, 4, 5)
4 5 6 7
8 9
Breadth-First Strategy
2 3 FRINGE = (4, 5, 6, 7)
4 5 6 7
8 9
Breadth-First Strategy
2 3 FRINGE = (5, 6, 7, 8)
4 5 6 7
8 9
Breadth-First Strategy
2 3 FRINGE = (6, 7, 8)
4 5 6 7
8 9
Breadth-First Strategy
2 3 FRINGE = (7, 8, 9)
4 5 6 7
8 9
Breadth-First Strategy
2 3 FRINGE = (8, 9)
4 5 6 7
8 9
Breadth-first search (BFS)
Advantages:
❑ BFS will provide a solution if any solution exists.
❑ If there are more than one solutions for a given
problem, then BFS will provide the minimal solution
which requires the least number of steps.
Disadvantages:
❑ It requires lots of memory since each level of the tree
must be saved into memory to expand the next level.
❑ BFS needs lots of time if the solution is far away from
the root node.
Depth-first search (BFS)
❑ It is called the depth-first search because it starts
from the root node and follows each path to its
greatest depth node before moving to the next
path.
Fringe stack:
A
Expanding A,
gives stack:
B
C
So, B next.
Depth-first search (BFS)
Expanding B,
gives stack:
D
E
C
So, D next.
Depth-first search (BFS)
Expanding D,
gives stack:
H
I
E
C
So, H next.
etc.
Depth-first search (BFS)
Stack: ?
So, ? next.
Depth-first search (BFS)
Stack: ?
So, ? next.
Depth-first search (BFS)
Stack: ?
So, ? next.
Depth-first search (BFS)
Stack: ?
So, ? next.
Depth-first search (BFS)
Stack: ?
So, ? next.
Depth-first search (BFS)
Breadth-first search (BFS)
Advantages:
❑ 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.
Disadvantages:
❑ 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.