Data Structures & AlgorithmsModerateGATE CS · ICPC regional
An undirected connected graph on the vertices H, K, L, V has the edges L–K, V–H, H–K, V–K, L–H, V–L. How many spanning trees does it have? (A spanning tree is a set of edges that connects all vertices with no cycle.)
- A. 16
- B. 3
- C. 8
- D. 20
Correct answer: A. 16
The Matrix-Tree theorem gives the count as any cofactor of the Laplacian, here 16. Choosing any 3 of the 6 edges gives 20 sets, but most of them contain a cycle or leave a vertex out.
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
- A directed acyclic graph has the vertices A, E, G, V, X, Z and the edges G→E, G→V, X→G, X→A, A→Z, Z→E. A topological order lists every…
- A tree has the vertices A, F, I, O, P, U, Y and the edges I–A, I–F, F–U, U–O, F–P, P–Y. What is the minimum number of vertices needed so…
- A tree has vertices with values in brackets: U[-2], B[7], H[5], A[7], N[-2], P[5], C[4], S[-1]. The edges are U–B, U–H, H–A, A–N, B–P…
- An undirected graph has the vertices A, J, Q, T, Y and the edges T–Q, T–A, Y–Q, Y–A, Q–A. What is its chromatic number, the least number…
- A tree has the vertices B, C, D, E, M, P, S, U, V, W and the edges U–B, U–C, C–W, B–V, U–M, M–D, D–P, B–S, W–E. A set D dominates the tree…
- A tree has vertices D, H, J, M, Q, R, U, W and weighted edges (weights in brackets): D–H (9), H–Q (5), H–W (5), Q–M (1), D–U (8), U–J (2)…