Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B
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 walks of length exactly 3 go from T to R?
- A. 3
- B. 19
- C. 1
- D. 5
Correct answer: D. 5
The (i, j) entry of the k-th power of the adjacency matrix counts walks of length k, giving 5. Simple paths from T to R give only 3, and walks of length 2 give 1.
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, 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…
- A connected undirected graph has the vertices A, F, I, M, Q, S, X and the edges M–Q, M–S, M–A, M–X, Q–S, S–F, A–I. How many bridges does…
- Bellman–Ford is run from source C on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: C→F…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→A (5), S→D (9), S→T (7), E→C (2), E→D (2), E→T…
- An undirected graph has the vertices D, L, N, R, X, Z and the edges N–L, Z–X, X–L, Z–D, L–R, Z–L, Z–N. How many simple cycles does it…
- An undirected graph has the vertices A, J, L, Q, W, X, Y and the edges L–J, L–X, L–W, L–A, Q–X, Q–A, J–Y, Y–W. What is the size of a…