Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

An undirected graph has the vertices D, M, R, V and the edges M–D, M–V, M–R, D–V, D–R, V–R. A walk may repeat vertices and edges. How many walks of length exactly 4 go from M to D?

  1. A. 7
  2. B. 20
  3. C. 81
  4. D. 5

Correct answer: B. 20

The (i, j) entry of the k-th power of the adjacency matrix counts walks of length k, giving 20. Simple paths from M to D give only 5, and walks of length 3 give 7.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic