Data Structures & AlgorithmsHardGATE CS · ICPC regional

An undirected graph has the vertices A, G, H, L, P and the edges L–G, H–P, A–H, H–G, H–L, A–P, P–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. 6
  2. B. 7
  3. C. 2
  4. D. 3

Correct answer: A. 6

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic