Reputation: 81
Are there any graph-problems that can be solved by DFS or BFS, but not the other? That is, does a graph-problem exist that is solvable by BFS, but not DFS, or vice-versa?
Upvotes: 0
Views: 724
Reputation: 39323
Yes: here is one such problem that can be solved by BFS but not DFS:
GAME RULES
PROBLEM
Search to see if it is possible for this game to ever end.
BFS APPROACH
DFS APPROACH
Upvotes: 1
Reputation: 65506
BFS but not DFS: unweighted shortest paths.
DFS but not BFS: lots of algorithms due to Tarjan, e.g., strongly connected components and biconnected components.
Upvotes: 4
Reputation: 71009
The simplest example is: find the minimal number of edges you must traverse to get from vertex A
to vertex B
in a given graph. This can be solved easily with BFS, but not with DFS. Finding the simple cycles in a graph, however is usually solved using DFS.
Upvotes: 2