Data Structures & AlgorithmsVery hardGATE CS
The 3 × 3 grid graph (9 vertices, 12 edges) has a diagonal edge added between its top-left corner and its centre vertex, giving a 13-edge graph. How many spanning trees does the new graph have?
- A. 204
- B. 288
- C. 360
- D. 192
Correct answer: C. 360
By the matrix-tree theorem the plain grid has 192 spanning trees. Trees of the new graph either avoid the new edge (192) or contain it (as many as the spanning trees of the grid with those two vertices merged), giving 360 in total.
More Coding Interview Problems questions
- 50 people stand in a circle numbered 1 to 50. Starting the count at person 1, every 7th person (counting the first as 1) is removed, and…
- How many subsets of {1, 2, ..., 15} (including the empty set) contain no two consecutive integers and have an even sum?
- How many integers n with 1 <= n <= 100000 are divisible by exactly one of the numbers 6, 10 and 15?
- How many primes p < 500 have p - 2 or p + 2 also prime (that is, belong to at least one twin-prime pair, counted as individual primes)?
- 0/1 knapsack with capacity 27: weights [13, 8, 9, 14, 12, 4, 11] and values [25, 19, 16, 27, 22, 8, 23] (item i has weight w[i] and value…
- How many structurally distinct binary trees with 8 nodes have at most 4 levels (a single root alone is 1 level)?