Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: An undirected graph has 10 vertices (0–9) and 6 edges: 0-1, 1-2, 3-4, 5-6, 6-7, 7-5. What is the minimum number of new edges that must be added so that the graph becomes connected?

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

Correct answer: A. 4

Connecting k components needs at least k−1 new edges, and that many suffice. Counting isolated vertices or the number of edges needed per component gives a larger number.

More Coding Interview Problems questions

Exams that ask this topic