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?

  1. A. 5
  2. B. 3
  3. C. 2
  4. 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.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic