Data Structures & AlgorithmsModerateGATE CS · ICPC regional

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

  1. A. 21
  2. B. 1440
  3. C. 12
  4. D. 9

Correct answer: C. 12

Enumerating the (n−1)-edge subsets that form a tree gives 12, and the matrix-tree theorem agrees. Counting all (n−1)-edge subsets (21) 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