GATE Computer ScienceVery hardGATE CS (PYQ pattern)

In the Josephus problem 30 people numbered 1 to 30 stand in a circle; counting starts at person 1 and every third person is eliminated (3, 6, 9, …) until one remains. Which person is the LAST ONE ELIMINATED (the 29th elimination), just before the survivor is determined?

  1. A. 29
  2. B. 2
  3. C. 11
  4. D. 19

Correct answer: D. 19

Simulating the circle: the eliminations end …, 10, 23, 11, 2, 19, and person 29 survives. So the 29th person eliminated is 19. The recurrence J(n) = (J(n−1) + 3) mod n gives only the survivor (29), not the elimination order.

More Algorithms questions

Exams that ask this topic