Data Structures & AlgorithmsHardGATE CS · ICPC regional
Count the spanning trees of the simple graph on vertices 0 to 5 with edges 0-1, 0-3, 1-4, 2-4, 3-4, 3-5. How many spanning trees does it have?
- A. 6
- B. 1296
- C. 1
- D. 4
Correct answer: D. 4
A spanning tree is a set of n − 1 edges that connects every vertex without a cycle. Choosing any n − 1 edges without checking for cycles or connectivity overcounts, and the labelled-tree formula n^(n−2) counts trees of K_n, not of this graph.
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
- How many spanning trees of the cycle Cn are there for n = 5?
- How many Hamiltonian cycles of the complete graph Kn (direction ignored) are there for n = 9?
- How many simple paths between two fixed vertices u and v of the complete graph Kn are there for n = 9?
- How many structurally different binary trees with n nodes (shape only, labels ignored) are there for n = 5?
- How many distinct binary trees that use each label 1 to n exactly once (shape and labels both matter) are there for n = 6?
- How many simple paths between two fixed vertices u and v of the complete graph Kn are there for n = 8?