Algorithms and Data Structures · Senior · Question 62 of 75
Why is DFS preferred over BFS for some puzzles despite BFS finding shortest solutions?
- 1BFS can't handle graphs that contain cycles
- ✓Correct answer: DFS stores one path; BFS stores a whole frontier
- 3DFS always finds the solution in fewer steps
Explanation
With branching factor b and depth d, BFS keeps up to bᵈ states in its queue. Iterative deepening DFS gets the best of both: shortest solutions with O(d) memory, at the cost of repeating the shallow levels.