GATE Computer ScienceHardGATE CS (PYQ pattern)

A DFS on a directed graph processes vertices in alphabetical order and each adjacency list in alphabetical order. Edges: A→B, A→C, A→E, B→D, B→E, C→D, D→A, D→E, E→C, F→E, F→G, G→F. How many edges are neither tree edges nor back edges (that is, forward or cross edges)?

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

Correct answer: B. 4

DFS from A visits A, B, D, E, C (tree edges AB, BD, DE, EC); back edges are D→A, C→D and G→F. Forward edges are A→C, A→E and B→E, and F→E is a cross edge (E already finished, discovered earlier): 3 + 1 = 4.

More Algorithms questions

Exams that ask this topic