Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The Josephus Problem

Given a sequence of numbers , we want to delete every other number, until one remains, such that: where is the remaining number

Example

Given n=12 we have: 1,2,3,4,5,6,7,8,9,10,11,12

Walking through the list we have: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12

Observe that the indicies (in our case the values) greater than 1, change such that the number at index 2, which was 2 became 3, so

Continuing with cycle of deletions we have:

1, 3, 5, 7, 9, 11

1, 5, 9

1, 9

By taking another example where n is odd, convince yourself that the change in values is as we loop back and cancel the starting .

Observe now that all we need to do is solve for the sequence we get after the first round of canceling so when sovling for we solve for where each element is .

That is:

Similarly with :

And we know the base case has the solution

The 3 equations form the recurrence for solving the problem