Data Structures & AlgorithmsVery hardICPC regional · GATE CS

Problem: What is the number of walks of length 4 that start and end at the same vertex in the complete graph K3 (vertices 0, 1, 2, each pair adjacent), summed over all starting vertices?

  1. A. 6
  2. B. 18
  3. C. 48
  4. D. 16

Correct answer: B. 18

Closed walks from a vertex in K3 number (2⁴ + 2)/3 = 6, so the trace over 3 vertices is 18. Forgetting to sum over starts gives 6, all walks of length 4 total 3 · 2⁴ = 48, and 16 assumes every walk from one vertex returns.

More Coding Interview Problems questions

Exams that ask this topic