Questions: Depth-First Search (DFS)

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

During a DFS of a directed graph, you encounter an edge (u, v) where v is already discovered and is an ancestor of u in the DFS tree. What does this edge indicate?

AA cross edge — v was discovered in a different DFS subtree
BA forward edge — v is a descendant of u
CA back edge — and this means there is a cycle in the graph
DA tree edge — v has not been fully processed yet
Question 2 Multiple Choice

You run DFS on a graph with V = 1,000 vertices and E = 50,000 edges. Which best describes the time complexity, and why?

AO(V²) — because DFS must compare every pair of vertices to decide if they're connected
BO(V + E) — because each vertex is processed once and each edge is examined once
CO(E log V) — because the DFS tree requires sorting edges by discovery order
DO(V × E) — because each vertex may trigger exploration of all edges
Question 3 True / False

In a DFS tree, if vertex v is a descendant of vertex u, then u's discovery time is less than v's discovery time, which is less than v's finish time, which is less than u's finish time.

TTrue
FFalse
Question 4 True / False

DFS is preferred over BFS when you need to find the shortest path between two vertices in an unweighted graph.

TTrue
FFalse
Question 5 Short Answer

Why do DFS discovery and finish timestamps enable topological sorting of a directed acyclic graph?

Think about your answer, then reveal below.