Data Structures & AlgorithmsModerateGATE CS · ICPC regional

Problem: An undirected graph has 8 vertices and 11 edges with exactly 2 connected components. What is the minimum number of edges that must be removed so the graph becomes a forest (no cycles)?

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

Correct answer: C. 5

A forest with c components on n vertices has n − c edges, so the number of edges to remove is m − (n − c). Removing m − n edges ignores the component count and removes one too few.

More Coding Interview Problems questions

Exams that ask this topic