Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B

An undirected graph has the vertices J, M, N, Q, R, S, W and the edges R–N, M–Q, Q–J, Q–W, M–S, M–R, Q–R, Q–S, M–J, R–S. How many simple cycles does it contain (a cycle visits distinct vertices and returns to its start; cycles that use the same edge set are the same cycle)?

  1. A. 13
  2. B. 3
  3. C. 5
  4. D. 12

Correct answer: D. 12

Enumerate edge subsets in which every vertex has degree 0 or 2 and the edges form one connected cycle: there are 12. The cyclomatic number m − n + 1 = 4 counts independent cycles, which is not the same count, and there are 5 triangles.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic