Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: A tree on 6 nodes has edges 1-2, 1-3, 1-4, 4-5, 4-6. How many pairs of edges share a common endpoint (that is, unordered pairs of distinct edges that touch at a vertex)?

  1. A. 10
  2. B. 12
  3. C. 6
  4. D. 15

Correct answer: C. 6

Nodes 1 and 4 have degree 3 and all others degree 1, so Σ C(d, 2) = 3 + 3 = 6. 10 counts all pairs of the 5 edges, d(d − 1) counts ordered pairs for 12, and 15 counts vertex pairs.

More Coding Interview Problems questions

Exams that ask this topic