Questions: Graph Traversal: Depth-First and Breadth-First Search

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

You need to find whether a directed graph contains a cycle. Which traversal algorithm is most naturally suited, and what does it detect?

ABFS, because it explores level by level and can detect cross-edges that indicate cycles
BDFS, because it detects back-edges — edges pointing to a vertex still on the current recursion stack
CEither algorithm works equally well, since both visit all vertices
DBFS, because its queue ensures vertices are visited in the order they were discovered, revealing repetitions
Question 2 Multiple Choice

In an unweighted graph, you want the shortest path from vertex S to every other reachable vertex. Which algorithm gives correct results, and why does the other one fail?

ADFS gives correct results; BFS may miss some vertices by terminating early
BBFS gives correct results; DFS may find a path but not the shortest one
CBoth give correct shortest paths because both visit all reachable vertices
DDFS gives correct results because its stack structure naturally prioritizes direct paths
Question 3 True / False

In an unweighted graph, BFS guarantees that each vertex is first discovered via the shortest path (fewest edges) from the source.

TTrue
FFalse
Question 4 True / False

DFS is faster than BFS in the worst case because it finds the target vertex sooner without exploring most levels.

TTrue
FFalse
Question 5 Short Answer

Why does using a queue (rather than a stack) cause BFS to find shortest paths in unweighted graphs?

Think about your answer, then reveal below.