Data Structures & AlgorithmsModerateGATE CS · ICPC regional

An undirected graph has the vertices H, J, K, N, P, Q, R and the edges K–R, K–P, Q–J, N–R, P–R, N–J, P–J, K–J, Q–R, H–J. 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. 2
  2. B. 12
  3. C. 4
  4. D. 13

Correct answer: B. 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 2 triangles.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic