Data Structures & AlgorithmsModerateGATE CS · ICPC regional

Count the spanning trees of the simple graph on vertices 0 to 5 with edges 0-1, 1-2, 1-3, 1-5, 2-3, 2-4, 2-5, 3-5, 4-5. How many spanning trees does it have?

  1. A. 126
  2. B. 4
  3. C. 1296
  4. D. 40

Correct answer: D. 40

A spanning tree is a set of n − 1 edges that connects every vertex without a cycle. Choosing any n − 1 edges without checking for cycles or connectivity overcounts, and the labelled-tree formula n^(n−2) counts trees of K_n, not of this graph.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic