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?

  1. A. 3
  2. B. 19
  3. C. 1
  4. 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.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic