Data Structures & AlgorithmsHardGATE CS · ICPC regional

A directed graph on vertices 0 to 7 has edges listed in this order: 0→1, 5→3, 3→0, 6→5, 7→6, 3→1, 2→5, 3→7, 5→4, 4→0, 6→7, 5→1, 1→0, 1→5. 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 back edges are there?

  1. A. 6
  2. B. 0
  3. C. 7
  4. D. 1

Correct answer: C. 7

Following the listed order gives tree 6, back 7, forward 0, cross 1 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