Data Structures & AlgorithmsHardICPC regional · GATE CS

Problem: Compute the number of paths of length exactly 3 from vertex 0 to vertex 2 in the undirected graph with edges 0-1, 1-2, 0-2, 2-3 (walks may repeat vertices and edges).

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

Correct answer: C. 4

Walk counting by repeated propagation over the adjacency lists gives every walk of length three that ends at vertex 2. Counting only simple paths would exclude walks that revisit vertices.

More Coding Interview Problems questions

Exams that ask this topic