Data Structures & AlgorithmsHardGATE CS · ICPC regional

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

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

Correct answer: C. 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