Quiz Space

Advanced Algorithms · Quiz 1 · 29 Oct 2023 · September 2023 term

Question 16: A game of Nim is played with n heaps that have a_1, \ldo…

Question 16

+2 marksOne correct option

A game of Nim is played with nn heaps that have a1,…,ana_1, \ldots, a_n stones (in other words, the ii-th heap has aia_i stones). The rules of Nim are not relevant to this problem. We only note that the first player wins if and only if the bitwise xor a1⊕⋯⊕ana_1 \oplus \cdots \oplus a_n is non-zero.

Alice and Bob are playing the following game. Both Alice and Bob have several boxes with heaps. In the first phase they pick exactly one heap from each box. In the second phase Alice chooses some nonempty subset of those heaps, and the regular Nim game starts on chosen heaps with Bob to move first.

Bob already knows which heaps Alice picked. Our goal is to help him to perform his picks so that he wins the game no matter which heaps Alice chooses during the second phase.

For example, suppose Alice has picked two heaps with one and two stones, and Bob has two boxes:

  • The first box has two heaps of sizes one and three stones.
  • The second box has two heaps of sizes two and four stones.

Then notice that no matter what Bob picks, Alice can always pick a subset whose XOR sum is zero:

  • If Bob picks 1,2, Alice picks 1,2,1,2 (1,1 or 2,2 would also work)
  • If Bob picks 1,4, Alice picks 1,1
  • If Bob picks 3,2, Alice picks 2,2
  • If Bob picks 3,4, Alice picks 1,2,3

However suppose Alice has picked one heap with one stone, and Bob has two boxes:

  • The first box has two heaps of sizes three and five stones.
  • The second box has two heaps of sizes seven and four stones.

Then Bob can pick the heap with three stones from the first box and seven stones from the second, and no matter which non-empty subset of heaps Alice picks from (1,3,7)(1, 3, 7), the XOR sum will be nonzero and Bob will win the game:

  • 3⊕2⊕7=63 \oplus 2 \oplus 7 = 6,
  • 3⊕2=1,3⊕7=4,2⊕7=53 \oplus 2 = 1, 3 \oplus 7 = 4, 2 \oplus 7 = 5,
  • and singleton subsets are already nonzero.

Assume that all heap sizes are positive integers between 11 and 2102^{10}.

Based on the above data, answer the given subquestions.

Suppose Bob has bb boxes. Let SiS_i denote set of heap sizes in the ii-th box. Let SS denote the set of heap sizes that Alice has. Interpret each heap size as a 10-length bit vector (adding leading zeroes as necessary) based on the binary representation of the number: for example, a heap of size 55 would be ⟨0,0,0,0,0,0,0,1,0,1⟩\langle 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 \rangle. Therefore, all heap sizes are elements of the vector space F210\mathbb{F}_2^{10}, where F2\mathbb{F}_2 is the field over two elements {0,1}\{0, 1\} with the operation being addition modulo two. If Bob selects heaps with sizes hi∈Sih_i \in S_i and these choices guarantee a win for Bob, then the set {hi1⩽i≤b}∪S\{h_i \quad 1 \leqslant i \leq b\} \cup S is:

  1. A
  2. B
  3. C
Show answer

Correct answer

  • B

Question 16 of 21 in the IIT Madras BS Advanced Algorithms (Advanced Algorithms) Quiz 1 paper sat on 29 Oct 2023, in the September 2023 term (IIT M DEGREE AN2 EXAM QPE2 29 Oct 2023). It carries 2 marks.

More questions from this paper

  1. Q1Which of the following statements is true? Statement 1: For every graph G and every maximum flow on G, there always exi…
  2. Q2Consider the following instance of the stable matching problem for 4 men (PQRS) and 4 women (WXYZ). P: W > X > Y > Z\ Q…
  3. Q3Consider 4 sets as follows: W = {w_1, w_2, w_3}, X = {x_1, x_2}, Y = {y_1, y_2, y_3} and Z = {z_1, z_2}. Suppose we are…
  4. Q4Figure question
  5. Q5Figure question
  6. Q6Figure question
  7. Q7There are N stones, numbered 1, 2, \ldots, N. For each (1 \leqslant i \leqslant N), the height of stone i is h_i. Assum…
  8. Q8There are N stones, numbered 1, 2, \ldots, N. For each (1 \leqslant i \leqslant N), the height of stone i is h_i. Assum…
  9. Q9There are N stones, numbered 1, 2, \ldots, N. For each (1 \leqslant i \leqslant N), the height of stone i is h_i. Assum…
  10. Q10Consider the following process. At all times you have a single positive integer x, which is initially equal to 1 . In e…
  11. Q11Consider the following process. At all times you have a single positive integer x, which is initially equal to 1 . In e…
  12. Q12Consider the following process. At all times you have a single positive integer x, which is initially equal to 1 . In e…
  13. Q13A game of Nim is played with n heaps that have a_1, \ldots, a_n stones (in other words, the i-th heap has a_i stones). …
  14. Q14A game of Nim is played with n heaps that have a_1, \ldots, a_n stones (in other words, the i-th heap has a_i stones). …
  15. Q15A game of Nim is played with n heaps that have a_1, \ldots, a_n stones (in other words, the i-th heap has a_i stones). …
  16. Q17A game of Nim is played with n heaps that have a_1, \ldots, a_n stones (in other words, the i-th heap has a_i stones). …
  17. Q18A game of Nim is played with n heaps that have a_1, \ldots, a_n stones (in other words, the i-th heap has a_i stones). …
  18. Q19A game of Nim is played with n heaps that have a_1, \ldots, a_n stones (in other words, the i-th heap has a_i stones). …
  19. Q20A game of Nim is played with n heaps that have a_1, \ldots, a_n stones (in other words, the i-th heap has a_i stones). …
  20. Q21A game of Nim is played with n heaps that have a_1, \ldots, a_n stones (in other words, the i-th heap has a_i stones). …