Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
An undirected graph has the vertices C, G, T, W, X and the edges C–T, C–G, W–T, W–G, W–X, T–G, G–X. A walk may repeat vertices and edges. How many walks of length exactly 3 go from C to W?
- A. 19
- B. 5
- C. 3
- D. 2
Correct answer: C. 3
The (i, j) entry of the k-th power of the adjacency matrix counts walks of length k, giving 3. Simple paths from C to W give only 6, and walks of length 2 give 2.
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 grid has 6 rows and 6 columns (top to bottom; '.' open, '#' blocked): ..#... .....# .##... ...... ..#..# ...... You may only move right…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 20. Two sequences of steps…
- A grid has 4 rows and 4 columns (top to bottom; '.' open, '#' blocked): ..## .... .... .... You may only move right or down, and you…
- An undirected connected graph on the vertices D, H, I, K, M has the edges H–K, I–K, D–H, D–M, D–K, D–I, H–M, M–K, H–I. How many spanning…
- An undirected graph has the vertices R, T, V, X and the edges T–R, T–X, T–V, R–V, X–V. A walk may repeat vertices and edges. How many…
- A connected undirected graph has the vertices B, D, J, K, Q, X and the edges X–J, X–B, X–D, J–B, J–Q, J–K, J–D, B–K, B–D. Parallel edges…