Step-by-Step Search Algorithms Practice
Perfect for classroom instruction and student practiceAn agent must find a path from the start (S) to the goal (G) in the following maze:
By completing this exercise, you will be able to:
| S (1,1) |
. (1,2) |
. (1,3) |
# (1,4) |
| # (2,1) |
. (2,2) |
# (2,3) |
. (2,4) |
| . (3,1) |
. (3,2) |
. (3,3) |
G (3,4) |
Define the search problem components
Level-by-level exploration using a queue
S to G?Deep exploration using a stack
S to G?Analyze the trade-offs between algorithms
| Aspect | BFS | DFS |
|---|---|---|
| Path Optimality | ✓ Optimal Always finds shortest path in unweighted graphs |
⚠ Not Optimal Finds any path, may be longer than optimal |
| Completeness | ✓ Complete Will find solution if one exists (finite state spaces) |
⚠ Conditionally Complete Complete with explored set, may get stuck in cycles without it |
| Time Complexity | O(b^d) Must explore all nodes at depth d |
O(b^m) May explore all paths to maximum depth |
| Space Complexity | O(b^d) Stores all nodes at current depth |
O(m) Only stores current path |
| Our Maze Results | Path: 5 moves, 8 expansions | Path: 5 moves, 7 expansions |
Deeper analysis and practical considerations
Key takeaways and algorithm comparison