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)?
- A. 6
- B. 7
- C. 2
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A grid has 4 rows and 7 columns (top to bottom; '.' open, '#' blocked): .#.##.. ..#..#. .....#. ....... You may only move right or down…
- A directed weighted graph has the arcs u→v (weight): F→K (4), F→U (1), F→H (13), K→F (12), U→F (13), U→K (4), U→L (8), L→F (2), L→K (2)…
- A connected undirected graph has the vertices C, K, L, P, U, X, Y and the edges L–X, X–C, X–Y, C–K, C–P, C–U, K–Y, K–P, Y–U, P–U. Parallel…
- A directed acyclic graph has the vertices C, J, P, U, X and the arcs P→C, P→X, U→C, J→C, C→X. Two players alternately move a single token…
- A grid has 3 rows and 4 columns with these values (top to bottom): 1832 3673 2187 A path moves between side-adjacent cells (up, down, left…
- A tree on the vertices J, L, M, N, T has the arcs T→J, J→N, L→T, M→T (each undirected edge is directed as shown). You may reverse the…