Data Structures & AlgorithmsHardProduct company OA

How many distinct spanning trees does the graph with vertices A, B, C, D and edges A–B, B–C, C–D, D–A, A–C (a 4-cycle plus one diagonal) have?

  1. A. 10
  2. B. 4
  3. C. 8
  4. D. 16

Correct answer: C. 8

Choose 3 of the 5 edges: C(5, 3) = 10 subsets. Exactly two of them contain a triangle (A–B, B–C, A–C and A–C, C–D, D–A) and so are not trees: 10 − 2 = 8. Kirchhoff's matrix-tree theorem gives the same. 16 is Cayley's count for the complete graph K₄, which has one more edge.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic