GATE Computer ScienceModerateGATE CS (PYQ pattern)

An undirected graph has 14 vertices, 20 edges and exactly 3 connected components. DFS is restarted from an unvisited vertex until all vertices are visited. How many tree edges and how many back edges does the DFS forest have, and what is the minimum number of edges whose removal leaves no cycle?

  1. A. 13 tree, 7 back, 7 removals
  2. B. 11 tree, 9 back, 9 removals
  3. C. 11 tree, 9 back, 7 removals
  4. D. 11 tree, 7 back, 9 removals

Correct answer: B. 11 tree, 9 back, 9 removals

A DFS forest has one tree per component, so 14 - 3 = 11 tree edges; in an undirected DFS every non-tree edge is a back edge: 20 - 11 = 9. Removing exactly those 9 leaves a spanning forest, and no fewer suffice because E - V + c = 20 - 14 + 3 = 9 independent cycles exist. Assuming a connected graph gives 13 and 7.

More Programming and Data Structures (GATE) questions

Exams that ask this topic