Data Structures & AlgorithmsHardGATE CS · Product Company SDE

Problem: The number of spanning trees of the complete graph K4 (4 labelled vertices, every pair joined by an edge) is what value? (Cayley's formula n^(n−2) may be used as a check.)

  1. A. 20
  2. B. 64
  3. C. 16
  4. D. 12

Correct answer: C. 16

Cayley's formula gives 4^(4−2) = 16; equivalently, of the C(6, 3) = 20 three-edge subsets, the 4 triangles are not trees. Counting every 3-edge subset gives 20, using n^(n−1) gives 64, and counting Hamiltonian paths only (4!/2) gives 12.

More Coding Interview Problems questions

Exams that ask this topic