GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A directed graph has adjacency lists (visited in the order listed): A: B, C; B: D, E; C: E, F; D: G; E: D, H; F: H, B; G: none; H: G, A. DFS starts at A, and the discovery and finish times use one counter that increments on every discovery and every finish (so times run from 1 to 16). How many back edges and how many cross edges does the DFS find, and what is the finish time of C?

  1. A. 2 back, 5 cross, f(C) = 15
  2. B. 1 back, 6 cross, f(C) = 13
  3. C. 1 back, 5 cross, f(C) = 15
  4. D. 1 back, 4 cross, f(C) = 16

Correct answer: C. 1 back, 5 cross, f(C) = 15

Run DFS in list order: discovery times {'A': 1, 'B': 2, 'D': 3, 'G': 4, 'E': 7, 'H': 8, 'C': 12, 'F': 13}, finish times {'G': 5, 'D': 6, 'H': 9, 'E': 10, 'B': 11, 'F': 14, 'C': 15, 'A': 16}. An edge to a gray vertex is a back edge, to a black vertex with earlier discovery a cross edge.

More Programming and Data Structures (GATE) questions

Exams that ask this topic