Professional Documents
Culture Documents
Unit 4 - Uninformed Search Techniques
Unit 4 - Uninformed Search Techniques
ARTIFICIAL
INTELLIGENCE
Unit 4
05/06/2024 Spring' 2024 2
Acknowledgment
• Some of the slides of this lecture have been taken from:
• The lecture slides of CS188 – “Introduction to Artificial Intelligence”
UC Berkeley
05/06/2024 Spring' 2024 3
Outline
• Uninformed Search Strategies
• Breadth First Search
• Depth First Search
• Depth Limited Search
• Iterative Deepening Search
05/06/2024 Spring' 2024 4
BFS – Explained
• In BFS, graph is searched from the root node in order of
the distance from the root
BFS - Explained
• BFS implementation uses a FIFO (first-in first-out) queue
Breadth-First Search
Strategy: expand a G
a shallowest b c
node first e
d f
Implementation: S h
Fringe is a FIFO p r
queue q
d e p
Search
b c e h r q
Tiers
a a h r p q f
p q f q c G
q c G a
a
05/06/2024 Spring' 2024 7
BFS - Comments
d is the
• Complete?
depth
• Yes
• Optimal?
• Yes, in a non-weighted graph
• Time Complexity
• O(bd)
• Space Complexity
• O(bd), d is depth of the solution, not the depth of the tree
05/06/2024 Spring' 2024 8
BFS – Comments
• Useful when
• Space is not a problem
• You want to find the solution containing the fewest arcs (Does not
consider cost of the solution)
• Few solutions may exist, and at least one has a short path length
• Infinite paths may exist – explores all of the search space, even
with infinite paths
• Poor method when
• All solutions have a long path length
• There is some heuristic knowledge available
05/06/2024 Spring' 2024 9
DFS – Explained
• Searching begins at the root node
Depth-First Search
Strategy: expand a a G
deepest node first b c
Implementation: Fringe e
d f
is a LIFO stack S h
p q r
d e p
b c e h r q
a a h r p q f
p q f q c G
q c G a
a
05/06/2024 Spring' 2024 11
DFS – Comments
• Complete?
• No, in case of loops the algorithm cycles indefinitely
• Optimal?
• No
• Space Complexity
• O(bd)
• Time Complexity
• O(bd)
d is the
depth
05/06/2024 Spring' 2024 12
DFS – Comments
• Appropriate when
• Space is restricted
• Many solutions exist, perhaps with long path lengths, particularly
for the case where nearly all paths lead to a solution
• The order of the neighbors of a node are added to the stack can be
tuned so that solutions are found on the first try (A smart or Lucky
Tie breaker)
• Not suitable when
• It is possible to get caught in infinite paths – when the graph is
infinite or when there are cycles in the graph
• Solutions exist at shallow depth – the search may look at many
long paths before finding the short solutions
05/06/2024 Spring' 2024 13
Activity
• Start Node – A
• Goal – G
• Path taken for DFS,
BFS and nodes
explored
• Status of queue/stack
on every move
05/06/2024 Spring' 2024 15
Variants of DFS
• Depth – Limited Search (DLS)
• Iterative Deepening Search (IDS)
05/06/2024 Spring' 2024 17
Exercise
• Find path from S to G
• For each DFS, DLS
(d=3), IDS, BFS
• Search tree constructed
during the search
• List of nodes in the order
in which they were
expanded
• State of the Queue when
the node was expanded
05/06/2024 Spring' 2024 22
Solution to DFS
05/06/2024 Spring' 2024 23
Homework
• Solutions for BFS and IDS are left as an exercise.