Data Structures & AlgorithmsModerateGATE CS · ICPC regional

A directed graph on vertices 0 to 5 has edges listed in this order: 3→0, 4→0, 5→3, 2→5, 0→3, 2→0, 5→4, 1→3, 0→2, 2→1. A depth-first search visits out-neighbours in the order their edges are listed, starts at 0 and then starts from the smallest unvisited vertex each time. Each edge is classified as tree (to an unvisited vertex), back (to a vertex still on the recursion stack), forward (to an already finished descendant) or cross (to any other finished vertex). How many tree edges are there?

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

Correct answer: D. 5

Following the listed order gives tree 5, back 3, forward 0, cross 2 edges. The other three classes are the classic mix-ups with the requested type.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic