Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
An undirected connected graph on the vertices D, U, W, X has the edges U–X, D–W, D–X, W–X, D–U. How many spanning trees does it have? (A spanning tree is a set of edges that connects all vertices with no cycle.)
- A. 4
- B. 10
- C. 8
- D. 2
Correct answer: C. 8
The Matrix-Tree theorem gives the count as any cofactor of the Laplacian, here 8. Choosing any 3 of the 5 edges gives 10 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 connected undirected graph has the vertices B, M, R, T, U and the edges U–T, U–M, U–R, T–R, T–B, M–B, R–B. Parallel edges are allowed…
- An undirected graph has the vertices A, D, F, P, U, Y and the edges P–A, Y–A, D–A, D–U, Y–F, D–F, P–F, U–A, Y–D, F–U. What is the minimum…
- A directed acyclic graph has the vertices D, L, P, Q, R, U, V and the edges V→R, Q→R, U→R, U→Q, U→D, U→P, L→Q. A topological order lists…
- Consider this recursive function: python def f(n): if n <= 0: return f(n - 2) if n % 3 == 0: f(n - 2) How many times is f called in total…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 22. Two sequences of steps…
- Starting from the integer 9, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…