Professional Documents
Culture Documents
The Josephus Problem: Recurrence Relations
The Josephus Problem: Recurrence Relations
Recurrence Relations
1 Introduction
In mathematics and computer science, the Josephus problem is a theoretical problem
related to a counting game. People are standing in a circle waiting to be executed.
Counting begins at a specified point in the circle and proceeds around the circle in a
fixed direction. At each step, a specified number of people are skipped and the next
executed. This is repeated until just one survivor remains.
According to Flavius Josephus, a Jewish historian in the 1st century, he and his soldiers
were trapped in a cave by Roman soldiers. They chose suicide over capture and drew
lots to see where they would stand in a circle. They decided that every second soldier
would be executed by the one next to them. Josephus states that by luck or possibly the
hand of God, he and another soldier remained until the end. He then convinced the last
soldier to surrender with him to the Romans.
Challenge: Given that n people are in the initial circle and every 2nd person is executed.
Find the position w(n) in which you should stand to survive.
1
Example
2 The pattern
Let n be the number of people in the circle, every 2nd person is killed and w(n) is the
number of the winning person, the survivor.
n w(n)
1 1
2 1
3 3
This table denotes the number of people in the circle n, and the winning position w(n).
Continue the table to find a pattern.
2
n w(n)
1 1
2 1
3 3
4 1
5 3
6 5
7 7
8 1
9 3
10 5
11 7
12 9
13 11
14 13
15 15
16 1
The table suggests an increasing odd sequence of winning positions. This is intuitive, as
all the even positions are killed in the first iteration around the circle. The pattern seems
to be increasing by 2 each time, and then resetting to 1 when n is a power of 2 (n takes
the form 2a where a is an integer).
Conjecture 2.1. If n = 2a then w(n) = 1. Where n is the total number of people and
w(n) is the winning position.
Well, any number can be written as a sum of powers of 2, where no power is repeated.
This is called binary notation. For our purposes, we want n to be written as the highest
power of 2 plus a remainder, where n = 2a + l
3
Example
11 = 8 + 2 + 1
= 23 + 21 + 20
= 23 + 3
Therefore, 11 = 23 + 3
88 = 64 + 16 + 8
= 26 + 24 + 23
= 26 + 24
Therefore, 88 = 26 + 24
Now that we have n in the form 2a + l, let’s see how we can find w(n).
First, complete the remainder l number of steps. Then, the amount of people left is 2a .
As we saw earlier, if n = 2a then w(n) = 1 or, the starting position.
4
Example
Now l = 3 people have been removed from the circle, leaving us with 11 − 3 = 8
people left. As we know from earlier, if n = 2a then w(n) = 1 (or, the starting
position).
We can see this works for all our previously worked out n values.
5
n 2a + l w(n) = 2l + 1
1 20 + 0 2(0) + 1 = 1
2 21 + 0 2(0) + 1 = 1
3 21 + 1 2(1) + 1 = 3
4 22 + 0 2(0) + 1 = 1
5 22 + 1 2(1) + 1 = 3
6 22 + 2 2(2) + 1 = 5
7 22 + 3 2(3) + 1 = 7
8 23 + 0 2(0) + 1 = 1
9 23 + 1 2(1) + 1 = 3
10 23 + 2 2(2) + 1 = 5
11 23 + 3 2(3) + 1 = 7
12 23 + 4 2(4) + 1 = 9
13 23 + 5 2(5) + 1 = 11
14 23 + 6 2(6) + 1 = 13
15 23 + 7 2(7) + 1 = 15
16 24 + 0 2(0) + 1 = 1
Example
88 = 26 + 24 + 23
= 26 + 16 + 8
= 26 + 24
Then w(n) = 2l + 1
w(n) = 2(24) + 1
= 49
6
3 Binary Representation
There is an elegant and interesting form we can use for this theorem if we use binary
representation. If we write n in binary, then shift the left-most digit from the beginning
to the end. It will then give us a binary representation of w(n).
Example
• Writing n = 88 in powers of 2
88 = 64 + 16 + 8
= 26 + 24 + 23
we get,
26 25 24 23 22 21 20
0 1 1 0 0 0 1
0110001 = 25 + 24 + 20
= 32 + 16 + 1
= 49