Data Structures & AlgorithmsModerateCodeforces Div 2 C · GATE CS
A directed graph has the vertices B, F, I, S and the arcs I→F, I→S, F→I, F→B, S→I, S→F, S→B, B→F, B→S. Count the directed Hamiltonian paths: sequences that list every vertex exactly once, where each consecutive pair is joined by an arc from the earlier to the later vertex. Sequences are counted over all possible starting vertices.
- A. 10
- B. 14
- C. 7
- D. 3
Correct answer: A. 10
A bitmask DP over (visited set, last vertex) counts directed Hamiltonian paths: 10 in total. Restricting to paths that start at I gives 3, and counting closed Hamiltonian cycles through I gives 2.
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
- An undirected graph has the vertices L, O, Q, Y, Z and the edges L–Z, O–Z, O–Y, Q–O, Q–Y, L–Y, L–Q, Y–Z. What is the minimum number of…
- An undirected graph has the vertices C, E, L, M, T and the edges L–E, L–T, M–C, E–C, C–T. In how many ways can each vertex be given one of…
- A directed acyclic graph has the vertices A, F, H, I, K, Q, R and the edges A→H, Q→A, Q→F, Q→H, R→F, F→H, F→K, F→I. A topological order…
- A tree has the vertices A, E, H, P, R, S, T, U, W, Y and the edges H–T, T–E, T–A, E–P, T–Y, A–R, Y–S, R–U, U–W. A set D dominates the tree…
- An undirected connected graph on 6 vertices has the edges (weights in brackets, all distinct): H–E (26), O–E (23), B–O (5), V–U (8), V–B…
- A tree has the vertices B, E, K, L, N, P, Y, Z and the edges N–E, N–B, E–L, N–K, E–Z, L–P, N–Y. What is the minimum number of vertices…