Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A directed graph has the vertices A, E, J, M and the arcs M→E, M→J, M→A, E→A, J→M, J→A, A→M, A→E, A→J. 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. 12
- B. 6
- C. 8
- D. 1
Correct answer: C. 8
A bitmask DP over (visited set, last vertex) counts directed Hamiltonian paths: 8 in total. Restricting to paths that start at M gives 2, and counting closed Hamiltonian cycles through M gives 1.
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 connected graph on 5 vertices has the edges (weights in brackets, all distinct): A–F (17), S–P (22), F–P (29), A–P (10), A–S…
- An undirected graph has the vertices D, M, P, Q, Y and the edges Q–P, Q–D, P–M, P–Y, M–D. A walk may repeat vertices and edges. How many…
- Starting from the integer 6, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- A tree has the vertices E, F, G, I, K, N, Y and the edges G–F, G–N, F–E, N–K, K–Y, K–I. A centroid is a vertex whose removal leaves no…
- An undirected graph on 7 vertices has the edges J–P, J–O, J–U, P–O, P–B, P–U, O–S, O–A, O–U, A–U. How many simple paths (no repeated…
- Grid with 4 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G.. G.G. .... .... Each step, which is a…