Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B

An undirected connected graph on the vertices B, H, O, P, S has the edges H–S, O–B, S–P, H–P, S–B, B–P, H–B. How many spanning trees does it have? (A spanning tree is a set of edges that connects all vertices with no cycle.)

  1. A. 17
  2. B. 16
  3. C. 8
  4. D. 35

Correct answer: B. 16

The Matrix-Tree theorem gives the count as any cofactor of the Laplacian, here 16. Choosing any 4 of the 7 edges gives 35 sets, but most of them contain a cycle or leave a vertex out.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic