Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B
A directed graph has the vertices E, G, Q, Z and the arcs E→Q, E→Z, G→E, G→Q, G→Z, Q→G, Q→Z, Z→E. 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. 7
- C. 1
- D. 6
Correct answer: B. 7
A bitmask DP over (visited set, last vertex) counts directed Hamiltonian paths: 7 in total. Restricting to paths that start at E gives 1, and counting closed Hamiltonian cycles through E 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
- A grid has 4 rows and 3 columns with these values (top to bottom): 121 725 748 239 A path moves between side-adjacent cells (up, down…
- A tree has vertices with weights in brackets: A[9], J[13], P[6], Q[8], M[2], V[3], Y[6], R[8]. The edges are A–J, J–P, A–Q, Q–M, P–V, Q–Y…
- A directed graph with no directed cycles has arcs u→v (weight) : I→X (0), I→C (8), I→T (7), X→C (2), C→T (-3), T→Z (0). Weights may be…
- An undirected graph has the vertices F, J, M, S, Z and the edges Z–F, Z–J, S–F, S–M, S–J, F–J. What is its chromatic number, the least…
- Consider this function: python def g(n): if n < 2: return n if n % 2 == 0: return g(n - 1) + g(n - 3) return g(n - 3) - 1 What value does…
- Consider this recursive function: python def f(n): if n <= 1: return f(n - 1) if n % 3 == 0: f(n - 2) How many times is f called in total…