Data Structures & AlgorithmsModerateCodeforces Div 2 C · GATE CS

An undirected graph has the vertices D, G, L, Q, R, X, Y and the edges R–G, Y–R, L–X, Y–G, D–R, Y–L, D–G. 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. 1
  2. B. 2
  3. C. 3
  4. D. 0

Correct answer: C. 3

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic