Data Structures & AlgorithmsModerateGATE CS · ICPC regional

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 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 K?

  1. A. 3
  2. B. 1
  3. C. 2
  4. D. 4

Correct answer: C. 2

Evaluate the Grundy values from the sinks backwards; the value of K is 2. Using the number of out-arcs in place of the Grundy values gives 3, and the longest path from K is 2.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic