Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

An undirected graph has the vertices E, F, G, I, Z and the edges G–I, G–Z, G–F, E–F, I–Z, I–F, Z–F. A walk may repeat vertices and edges. How many walks of length exactly 3 go from G to E?

  1. A. 30
  2. B. 2
  3. C. 5
  4. D. 1

Correct answer: B. 2

The (i, j) entry of the k-th power of the adjacency matrix counts walks of length k, giving 2. Simple paths from G to E give only 5, and walks of length 2 give 1.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic