Data Structures & AlgorithmsVery hardGATE CS · Product-company placement

DFS runs on the directed graph with adjacency lists A: BDF; B: FG; C: ABE; D: G; E: –; F: D; G: A, starting at A, scanning lists in the order shown and restarting from the alphabetically first unvisited vertex. How are the 11 edges classified?

  1. A. tree 5, back 1, forward 2, cross 3
  2. B. tree 5, back 1, forward 3, cross 2
  3. C. tree 5, back 1, forward 1, cross 4
  4. D. tree 5, back 2, forward 3, cross 1

Correct answer: B. tree 5, back 1, forward 3, cross 2

An edge to a grey (unfinished) vertex is a back edge; to a finished vertex it is forward if that vertex is a descendant (discovered later), otherwise cross. Timestamps give tree 5, back 1, forward 3, cross 2.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic