Data Structures & AlgorithmsHardGATE CS · ICPC regional

Problem: How many simple cycles (cycles that visit no vertex twice, with 3 or more vertices) does the complete undirected graph K4 on vertices 1–4 contain?

  1. A. 4
  2. B. 14
  3. C. 10
  4. D. 7

Correct answer: D. 7

K4 has C(4, 3) = 4 triangles and (4 − 1)!/2 = 3 Hamiltonian 4-cycles, so 7 simple cycles. Counting triangles only gives 4, counting both directions of each cycle gives 14, and counting the 3! vertex orders of a 4-cycle without dividing by 2 gives 4 + 6 = 10.

More Coding Interview Problems questions

Exams that ask this topic