Data Structures & AlgorithmsHardGATE CS · ICPC regional

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

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

Correct answer: A. 3

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