Data Structures & AlgorithmsHardGATE CS · ICPC regional
A directed graph has the vertices J, K, L, R, W and the arcs W→K, W→L, W→J, K→W, K→L, K→R, L→W, L→K, L→J, J→L, R→K, R→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. 8
- B. 3
- C. 16
- D. 11
Correct answer: D. 11
A bitmask DP over (visited set, last vertex) counts directed Hamiltonian paths: 11 in total. Restricting to paths that start at W gives 3, and counting closed Hamiltonian cycles through W 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
- The directed acyclic graph has the vertices C, I, J, R, Y, Z and the arcs C→R, Z→J, R→Y, I→Z, Z→Y, C→Y, Z→C, Y→J, I→C, I→J, Z→R, R→J. How…
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, Q4, Q5, with edges P1–Q1, P3–Q1, P3–Q5, P1–Q5, P2–Q3. What is…
- A connected undirected graph has the vertices A, E, G, J, P, Q, Z and the edges Z–P, Z–J, Z–E, Z–A, P–J, P–G, J–E, A–Q. How many bridges…
- An undirected graph has the vertices A, B, J, Q, Y and the edges Q–J, Q–B, Y–J, Y–B, A–J. A walk may repeat vertices and edges. How many…
- Consider this recursive function: python def f(n): if n <= 1: return f(n - 1) if n % 2 == 0: f(n - 3) How many times is f called in total…