Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

Problem: Vertices 1–5 of a directed graph have arcs 1→2, 2→3, 3→1, 3→4, 4→5, 5→4, and 1→5. Using DFS from vertex 1, how many back edges (edges to an ancestor on the current DFS stack) are found? Visit neighbours in increasing order.

  1. A. 3
  2. B. 2
  3. C. 1
  4. D. 4

Correct answer: B. 2

In a DFS of a directed graph, a back edge is one that points to a vertex still on the recursion stack. Edges into finished vertices are forward or cross edges and are not counted.

More Coding Interview Problems questions

Exams that ask this topic