Data Structures & AlgorithmsHardGATE CS · ICPC regional

Simple undirected graph on vertices 0 to 3 with edges: 0–2, 2–3, 1–2, 0–3, 1–3, 0–1. How many spanning trees does it have (edge subsets that connect all vertices and contain no cycle)?

  1. A. 16
  2. B. 20
  3. C. 96
  4. D. 8

Correct answer: A. 16

Enumerating the (n−1)-edge subsets that form a tree gives 16, and the matrix-tree theorem agrees. Counting all (n−1)-edge subsets (20) includes disconnected sets, and counting ordered edge lists multiplies by (n−1)!.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic