Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

An undirected graph has the vertices C, G, T, W, X and the edges C–T, C–G, W–T, W–G, W–X, T–G, G–X. A walk may repeat vertices and edges. How many walks of length exactly 3 go from C to W?

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

Correct answer: C. 3

The (i, j) entry of the k-th power of the adjacency matrix counts walks of length k, giving 3. Simple paths from C to W give only 6, and walks of length 2 give 2.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic