Data Structures & AlgorithmsVery hardICPC regional · CAT · MBA placement

Problem: The number of ways to choose 3 vertices from a graph's vertex set of size n = 12 such that no two chosen vertices are adjacent in a cycle C12 (vertex i is adjacent to i±1 mod 12). Compute the count.

  1. A. 220
  2. B. 336
  3. C. 112
  4. D. 120

Correct answer: C. 112

Independent k-sets of a cycle number n/(n − k) · C(n − k, k) = 12/9 · C(9, 3) = 112. A path (no wrap-around) gives C(10, 3) = 120, ignoring adjacency gives C(12, 3) = 220, and forgetting to divide 12 · C(8, 2) by k = 3 gives 336.

More Coding Interview Problems questions

Exams that ask this topic