You are on page 1of 7

The Josephus Problem

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

We have 10 people and each 2nd person is killed.

So, n = 10. Start at position 1, clockwise, and eliminate one at a time.

The elimination order is 2, 4, 6, 8, 10, 3, 7, 1, 9. Position 5 survives.

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.

When the circle is made up of 1 person, position 1 wins. w(1) = 1


When the circle is made up of 2 people, position 1 wins. w(2) = 1
When the circle is made up of 3 people, position 3 wins. w(3) = 3

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.

2.1 Finding w(n)


So, what happens in between the numbers that are a power of 2?

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

• Write n = 11 in the form n = 2a + l

11 = 8 + 2 + 1
= 23 + 21 + 20
= 23 + 3

Therefore, 11 = 23 + 3

• Writing n = 88 in the form n = 2a + l

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.

Let’s take our previous example of n = 11.

4
Example

We know 11 = 23 + 3, so let’s complete 3 steps.

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).

8 = 23 so w(n) = The person who begins the round.


The next person to act is position 7, which means 7 is the winning position.

The winning position w(n) is 2l + 1


7 = 2(3) + 1

Theorem 2.1.1 If n = 2a + l, where l < 2a , then w(n) = 2l + 1.

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

• When n = 88, what is w(n)?

Write n = 88 in the form n = 2a + l, where l < 2a .

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).

Let’s use our previous example of n = 88.

Example

• Writing n = 88 in powers of 2

88 = 64 + 16 + 8
= 26 + 24 + 23

Converting this to binary


26 25 24 23 22 21 20
1 0 1 1 0 0 0
Therefore, binary notation for 88 is 1011000. Shifting the first digit to the end,

we get,

26 25 24 23 22 21 20
0 1 1 0 0 0 1

0110001 = 25 + 24 + 20
= 32 + 16 + 1
= 49

You might also like