Data Structures & AlgorithmsHardICPC regional · GATE CS

Problem: On the complete graph K4 (vertices 0–3, every pair adjacent), how many walks of exactly 4 edges start at vertex 0? A walk may repeat vertices and edges, and reversing is allowed.

  1. A. 21
  2. B. 256
  3. C. 81
  4. D. 108

Correct answer: C. 81

Each step has 3 neighbours in K4, so 3⁴ = 81 walks. Those returning to 0 number 21, allowing self-loops gives 4⁴ = 256, and 4 · 3³ = 108 wrongly gives the first step 4 choices.

More Coding Interview Problems questions

Exams that ask this topic