Data Structures & AlgorithmsModerateGATE CS · ICPC regional
A directed acyclic graph has the vertices C, G, K, P, W, X, Z and the arcs Z→X, Z→G, Z→K, C→W, C→K, P→X, P→K, X→W, W→K, G→K. 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 Z?
- A. 2
- B. 1
- C. 4
- D. 3
Correct answer: A. 2
Evaluate the Grundy values from the sinks backwards; the value of Z is 2. Using the number of out-arcs in place of the Grundy values gives 2, and the longest path from Z 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
- An undirected graph has the vertices H, J, K, N, P, Q, R and the edges K–R, K–P, Q–J, N–R, P–R, N–J, P–J, K–J, Q–R, H–J. How many simple…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {2, 3} and s ≤ the pile size. The player who…
- A directed graph has the vertices B, H, L, Q, R, T, U, Z and the arcs B→L, B→H, B→R, B→Q, L→B, L→Z, L→H, Z→B, Z→L, Z→T, H→L, H→U, R→B…
- The directed acyclic graph has the vertices A, I, L, P, Q, W and the arcs W→P, I→A, W→I, L→I, Q→A, L→W, L→Q, L→A. How many distinct…
- An undirected graph has the vertices B, G, S, T, Y and the edges S–B, G–S, S–Y, S–T, B–T, G–Y, B–Y. What is the minimum number of edges…
- A directed acyclic graph has the vertices A, B, K, S, X, Y and the edges B→K, B→S, B→Y, B→X, S→K, Y→S, Y→X. A topological order lists…