Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B
An undirected graph has the vertices E, J, K, M, X and the edges X–M, X–K, X–J, M–J, K–J, K–E. A walk may repeat vertices and edges. How many walks of length exactly 3 go from X to M?
- A. 7
- B. 1
- C. 21
- 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 X to M 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
- Cities I, P, S, U, X are joined by roads with these travel costs: U–S 12, U–I 1, U–P 20, U–X 18, S–I 11, S–P 13, S–X 7, I–P 19, I–X 6, P–X…
- An undirected connected graph on 5 vertices has the edges (weights in brackets, all distinct): J–I (26), C–W (25), X–W (27), I–W (24), I–X…
- A tree has vertices with weights in brackets: D[7], N[2], H[11], W[9], L[10], T[5], F[14]. The edges are D–N, N–H, D–W, N–L, W–T, N–F. A…
- A connected undirected graph has the vertices I, K, N, P, U, W and the edges U–W, U–N, U–P, W–K, W–I, N–K, N–I. How many bridges does it…
- An undirected graph on 7 vertices has the edges G–T, G–H, T–E, T–X, E–O, E–H, E–B, O–B. How many simple paths (no repeated vertex) go from…
- A connected undirected graph has the vertices H, K, M, N, R, S, V and the edges V–H, H–S, H–K, H–N, H–M, S–R, N–M. How many bridges does…