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)?
- A. 21
- B. 1440
- C. 12
- 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)!.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Simple undirected graph on vertices 0 to 3 with edges: 1–2, 0–3, 0–1, 0–2, 2–3. How many spanning trees does it have (edge subsets that…
- Simple undirected graph on vertices 0 to 3 with edges: 0–1, 0–2, 1–3, 1–2, 2–3. How many spanning trees does it have (edge subsets that…
- Simple undirected graph on vertices 0 to 5 with edges: 3–4, 1–2, 3–5, 1–3, 0–3, 1–4, 1–5, 2–4. How many spanning trees does it have (edge…
- Simple undirected graph on vertices 0 to 3 with edges: 2–3, 1–2, 0–2, 1–3, 0–3. How many spanning trees does it have (edge subsets that…
- Simple undirected graph on vertices 0 to 3 with edges: 0–2, 1–3, 2–3, 1–2, 0–1. How many spanning trees does it have (edge subsets that…
- Simple undirected graph on vertices 0 to 4 with edges: 0–1, 3–4, 2–4, 0–3, 2–3, 1–2, 0–2, 1–4. How many spanning trees does it have (edge…