Josephus Problem — Definition, Formula & Examples
The Josephus Problem is a counting puzzle where people stand in a circle and every -th person is eliminated until one survivor remains. The goal is to determine the position of that last person standing.
Given people labeled arranged in a circle, with every -th person removed sequentially, the Josephus function returns the position (using 0-indexed labeling) of the survivor. It satisfies the recurrence with base case .
Key Formula
Where:
- = Total number of people in the circle
- = Every k-th person is eliminated
- = 0-indexed position of the survivor
How It Works
Start at person 1 and count around the circle. Every -th person is removed, and counting resumes from the next person. The circle shrinks by one each round until a single person remains. For the special case , a closed-form solution exists using the binary representation of . For general , you apply the recurrence relation bottom-up from up to , then convert to 1-indexed by adding 1.
Worked Example
Problem: Seven people stand in a circle numbered 1 through 7. Every 3rd person is eliminated. Which position survives?
Base case: With 1 person, the survivor is at position 0.
Build up: Apply the recurrence for each value of from 2 to 7.
Continue: Keep applying the formula step by step.
Finish: Complete the remaining steps.
Convert to 1-indexed: Add 1 to convert from 0-indexed to 1-indexed position.
Answer: Person in position 4 is the last survivor.
Why It Matters
The Josephus Problem appears in discrete mathematics and algorithms courses as a classic example of solving problems via recurrence relations. It also illustrates how modular arithmetic governs cyclic structures, a pattern that arises in circular buffer management and round-robin scheduling in computer science.
Common Mistakes
Mistake: Confusing 0-indexed and 1-indexed positions in the final answer.
Correction: The recurrence produces a 0-indexed result. Add 1 at the end if the problem labels people starting from 1.
