Data Structures & AlgorithmsModerateGATE CS · ICPC regional
A directed graph has the vertices C, I, L, R, U and the arcs I→U, I→C, I→L, R→I, R→U, R→C, R→L, U→C, C→I, C→L, L→U. 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. 11
- B. 0
- C. 6
- D. 7
Correct answer: C. 6
A bitmask DP over (visited set, last vertex) counts directed Hamiltonian paths: 6 in total. Restricting to paths that start at I gives 0, and counting closed Hamiltonian cycles through I gives 0.
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 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G.G G.G. .... Each step, which is a move…
- Starting from the integer 6, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- A connected undirected graph has the vertices D, L, Q, R, T, Y and the edges Y–D, Y–T, D–Q, D–R, D–L, R–T, R–L, T–L. Parallel edges are…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, with edges P4–Q2, P3–Q3, P4–Q3, P1–Q3, P2–Q1, P4–Q1. What is the…
- Consider this recursive function: python def f(n): if n <= 1: return f(n - 2) if n % 2 == 0: f(n - 3) How many times is f called in total…
- An undirected graph has the vertices E, G, I, L and the edges G–I, G–E, I–L, L–E. A walk may repeat vertices and edges. How many walks of…