Data Structures & AlgorithmsModerateGATE CS · ICPC regional
A directed acyclic graph has the vertices F, H, J, K, L, N, R and the arcs H→J, H→R, H→N, K→J, K→F, K→N, L→R, L→F, J→R, J→F, J→N, R→F. Two players alternately move a single token along an arc. A player who cannot move loses. The Grundy (nim) value of a vertex is the mex (smallest non-negative integer not present) of the Grundy values of its out-neighbours, with 0 for a sink. What is the Grundy value of H?
- A. 5
- B. 3
- C. 2
- D. 4
Correct answer: B. 3
Evaluate the Grundy values from the sinks backwards; the value of H is 3. Using the number of out-arcs in place of the Grundy values gives 2, and the longest path from H is 3.
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 directed acyclic graph has the vertices B, H, K, O, W and the arcs K→B, K→W, K→O, B→H, B→O, W→O. Two players alternately move a single…
- On an 6×6 chessboard, rows and columns are numbered 0 to 5, and squares are written (row, column). A knight moves in the usual L-shape…
- A connected undirected graph has the vertices E, F, J, K, L, W, Y, Z and the edges Y–E, Y–W, E–Z, E–L, E–W, E–J, Z–L, Z–F, W–K. Parallel…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→C (7), B→E (5), D→B (7), D→C (2), C→B (9), C→E…
- Consider this function: python def g(n): if n < 2: return n if n % 2 == 0: return g(n - 3) + g(n - 3) return g(n - 3) - 1 What value does…
- A tree has vertices B, H, L, V, W, X, Y and weighted edges (weights in brackets): L–H (7), L–B (2), L–V (3), L–Y (7), L–X (3), X–W (1)…