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)?
- A. 1
- B. 2
- C. 3
- 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.
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
- Grid with 3 rows and 3 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G. G.. ... Each step, which is a move to…
- Two unmarked jugs hold 7 litres and 9 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- A tree has vertices E, H, I, K, L, M, V, Z and weighted edges (weights in brackets): I–E (5), I–L (9), I–H (9), E–K (6), K–Z (7), E–M (1)…
- A directed acyclic graph has the vertices D, E, I, Q, R, U, Z and the edges D→R, D→E, Z→D, Z→R, Z→Q, Z→E, R→U, Q→D, I→D. A topological…
- A directed graph has the vertices H, J, M, T, X, Y and the arcs M→T, M→X, T→X, J→Y, X→Y, Y→T, Y→J. How many strongly connected components…
- A tree has the vertices D, E, I, L, O, P, Q, T, W and the edges T–D, D–L, L–Q, Q–E, T–I, E–O, T–P, D–W. A centroid is a vertex whose…