Choose BFS over DFS when
Athe graph is a tree, not a general graph
Byou need cycle detection in a directed graph
Cyou need the shortest hop count from a source to other vertices
Dyou want to compute discovery and finish timestamps
Answer & Solution
Correct answer: C. you need the shortest hop count from a source to other vertices
BFS reaches vertices by increasing edge distance, so it naturally gives shortest hop counts in unweighted graphs. Cycle detection and timestamps are DFS specialities (back edges flag cycles, discovery/finish times power topological sort and SCC). Trees can use either; the choice depends on the question, not the graph type.
Related questions
An NP-hard problem differs from an NP-complete one because NP-hard problemsThe first problem proved to be NP-complete wasA problem X is NP-complete if and only ifWhy does theoretical computer science draw the line at 'polynomial-time' for tractability?Which set inclusion is established (i.e., proven, not open)?The class NP is the set of decision problems for whichFloyd-Warshall detects the presence of a negative cycle byTopological sort is well-defined for