Data Structures & AlgorithmsHardWipro NLTH · Graphs

A depth-first search runs on a directed graph with edges A->B, A->C, B->D, C->E, D->E, D->B, E->F, F->C, G->A, G->F, starting from A and then from any unvisited vertex, always taking neighbours alphabetically. How many back edges (edges to an ancestor still on the recursion stack) are found?

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

Correct answer: A. 2

The search goes A, B, D (D->B is a back edge), E, F, C (C->E is a back edge); G's edges are cross edges.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic