Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
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 connect all vertices and contain no cycle)?
- A. 10
- B. 48
- C. 5
- D. 8
Correct answer: D. 8
Enumerating the (n−1)-edge subsets that form a tree gives 8, and the matrix-tree theorem agrees. Counting all (n−1)-edge subsets (10) 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 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…
- Simple undirected graph on vertices 0 to 3 with edges: 1–2, 0–1, 2–3, 1–3, 0–2, 0–3. How many spanning trees does it have (edge subsets…
- Undirected weighted graph on vertices 0 to 6 with edges: 4–5 (1), 2–6 (13), 0–6 (11), 0–1 (2), 2–4 (4), 0–4 (4), 0–5 (9), 5–6 (15), 4–6…
- Undirected weighted graph on vertices 0 to 5 with edges: 0–1 (10), 2–3 (9), 1–3 (2), 3–5 (10), 1–2 (3), 2–4 (9), 0–2 (13), 0–3 (6), 1–4…
- Undirected weighted graph on vertices 0 to 4 with edges: 0–1 (8), 0–3 (5), 1–3 (6), 2–3 (7), 1–2 (10), 3–4 (15). Over all paths from 0 to…
- Undirected weighted graph on vertices 0 to 5 with edges: 2–4 (14), 2–5 (5), 3–5 (5), 3–4 (4), 1–2 (11), 1–4 (10), 0–2 (13), 2–3 (9), 0–3…