Start learning →

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.
Practise this question with Quill — GATE CSE →

Keep practising Algorithms

Browse all Algorithms questions for GATE CSE, or explore more Computer Science topics.

Start a Algorithms lesson →
Related questions