Lecture 03.2: Uninformed Search (BFS & DFS)
A deep dive into uninformed search strategies, exploring Breadth-First Search and Depth-First Search with Mermaid diagrams.
Uninformed Search Strategies: Looking Blindly
Uninformed search strategies use only the information available in the problem definition. They can generate successors and distinguish a goal state from a non-goal state, but they have no concept of which non-goal states are "more promising."
All uninformed strategies are distinguished simply by the order in which nodes are expanded.
Search algorithms are evaluated based on four criteria:
- Completeness: Is the algorithm guaranteed to find a solution when there is one?
- Optimality: Does the strategy find the optimal (lowest cost) solution?
- Time complexity: How long does it take to find a solution?
- Space complexity: How much memory is needed to perform the search?
1. Breadth-First Search (BFS)
In BFS, the root node is expanded first, followed by all successors of the root node, and then their successors, level by level. It uses a FIFO Queue to ensure nodes are visited in the order they are discovered.
Visualizing BFS Expansion
The following tree demonstrates the order of node expansion in BFS. Notice how it completes an entire depth level before moving deeper.
BFS Complexity
Assume every node has successors (branching factor), and the shallowest goal is at depth .
- Complete? Yes (if is finite).
- Optimal? Yes (but only if the path cost is a non-decreasing function of the depth, e.g., if step cost is always 1).
- Time Complexity: .
- Space Complexity: . Every node must reside in memory (the queue). Space is the biggest problem for BFS!
2. Depth-First Search (DFS)
In DFS, the search algorithm dives as deep as possible down one path before backtracking. It expands the deepest unexpanded node first, typically using a LIFO Stack (or recursion).
Visualizing DFS Expansion
Notice how DFS plunges down the left-most branch entirely before exploring siblings.
DFS Complexity
Assume a maximum depth of the state space , and branching factor .
- Complete? No. It fails in infinite-depth spaces or spaces with loops. It can be made complete in finite spaces if modified to avoid repeated states.
- Optimal? No. It will return the first solution it finds, even if a shallower one exists on another branch.
- Time Complexity: . This is terrible if is much larger than . However, if solutions are dense, it may be much faster than BFS.
- Space Complexity: . DFS only needs to store a single path from the root to a leaf node, alongside the unexpanded sibling nodes for each node on the path. This linear space requirement is its biggest advantage!