Recurrent Problem:
Generalizing the Josephus Problem
CSE547: Discrete Mathematics
Fall 2015
C HEN -W EI WANG
Recall:
Specification of the Josephus Problem
• Given: n people numbered 1 to n
around a circule
• Rules:
◦ Eliminate every second
remaining person until only one
survives.
• Problem: Determine the
survivor’s number.
2 of 14
Pattern of the Closed Form Solution to J(n)
3 of 14
n
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
J(n)
1
1
3
1
3
5
7
1
3
5
7
9
11
13
15
1
Recall: Recurrence Relation and
Closed-Form Solution for J(n)
Consider cases of the starting number being even or odd:
J(1)
= 1
J(2n)
= 2J(n) − 1 for n > 0
J(2n + 1) = 2J(n) + 1 for n > 0
For a given number that belongs to the group starting with 2g and
is h away from the beginning of its belonging group, we have the
following closed-form solution:
J(2g + h) = 2h + 1
4 of 14
for g ≥ 0 and 0 ≤ h < 2g
Another look at the problem
• Putting 1 .. n into groups, each starting with a power of 2 is the
critical step in finding the closed-form solution .
• Recall how we represent n in the base-10 number system:
n = 2g + h
for g ≥ 0 and 0 ≤ h < 2g
• Natural to look at the binary representation of input n:
n = (bg bg−1 . . . b1 b0 )2
where bi ∈ {0, 1}, for 0 ≤ i ≤ g, and bg = 1
• That is:
n = 1 · 2g + bg−1 · 2g−1 + · · · + b1 · 21 + b0 · 20
5 of 14
Another look at the closed-form solution
• Recall how we represent the closed-form solution in base of 10:
J(2g + h) = 2h + 1
• Now in the base-2 number system:
J( (bg bg−1 . . . b1 b0 )2 )
= {definition of the close-form solution}
2 · (0bg−1 . . . b1 b0 )2 + 1
= {multiplication: shift to left}
(bg−1 . . . b1 b0 0)2 + 1
= {addition}
(bg−1 . . . b1 b0 1)2
= {bg = 1}
(bg−1 . . . b1 b0 bg )2
How do you interpret this result? A one-bit left, circular shift !
6 of 14
Generalizing the Recurrence Relation for J(n)
Again, this is the recurrence relation for J(n):
J(1)
= 1
J(2n)
= 2J(n) − 1 for n > 0
J(2n + 1) = 2J(n) + 1 for n > 0
We generalize it by introducing constants α, β, and γ:
f (1)
= α
f (2n + j) = 2f (n) + βj
for n > 0, j ∈ {0, 1}, β0 = β, β1 = γ
The original problem for J(n) is now an instance of the above
generalization with α = 1, β = −1, and γ = 1.
7 of 14
Solution to the General Recurrence
f(n)
= {binary representation of n}
f ( (bg bg−1 . . . b1 b0 )2 )
= {(bg bg−1 . . . b1 b0 )2 = 2 · (bg bg−1 . . . b1 )2 + b0 , recurrence}
2f ( (bg bg−1 . . . b1 )2 ) + βb0
= {(bg bg−1 . . . b1 )2 = 2 · (bg bg−1 . . . b2 )2 + b1 , recurrence}
4f ( (bg bg−1 . . . b2 )2 ) + 2βb1 + βb0
...
= {(bg bg−1 )2 = 2 · bg + bg−1 , recurrence}
2g · f ( (bg )2 ) + 2g−1 βbg−1 + · · · + 2βb1 + βb0
= {bg = 1 and f (1) = α}
2g α + 2g−1 βbg−1 + · · · + 2βb1 + βb0
That is: f ( (bg bg−1 . . . b1 b0 )2 ) = (αβbg−1 βbg−2 . . . βb1 βb0 )2
8 of 14
Solution to the General Recurrence: Example
Now consider the original Josephus problem
where α = 1, β = −1, and γ = 1.
=
=
=
=
=
f(100)
{binary representation of 100}
f ( (1100100)2 )
{solution: 2g α + 2g−1 βbg−1 + · · · + 2βb1 + βb0 }
26 · 1 + 25 · β1 + 24 · β0 + 23 · β0 + 22 · β1 + 21 · β0 + 20 · β0
{β0 = β = −1 and β1 = γ = 1}
26 · 1 + 25 · 1 + 24 · −1 + 23 · −1 + 22 · 1 + 21 · −1 + 20 · −1
{simplify powers of 2}
64 + 32 − 16 − 8 + 4 − 2 − 1
{arithmetic}
73
Matches:
J(100) = J(26 + 36) = 2 · 36 + 1 = 73
9 of 14
Generalizing the Recurrence Relation Further
Recall: We generalized the Josephus problem by introducing
constants α, β, and γ:
f (1)
= α
f (2n + j) = 2f (n) + βj
for n > 0, j ∈ {0, 1}, β0 = β, β1 = γ
Now we generalize the above recurrence relation further by
introducing constants d (input radix) and c (output radix):
f (j)
= αj
f ( d · n + j) = c · f (n) + βj
10 of 14
for 1 ≤ j < d
for n > 0, 0 ≤ j < d
Solution to the General Recurrence
Recall the closed-form solution to the previous general recurrence:
f ( (bg bg−1 . . . b1 b0 )2 ) = (αβbg−1 βbg−2 . . . βb1 βb0 )2
Similarly, we have the solution to the ultimate general recurrence:
f ( (bg bg−1 . . . b1 b0 )d ) = (αbg βbg−1 βbg−2 . . . βb1 βb0 )c
11 of 14
Solution to the Ultimate General Recurrence:
Exercise
Given the recurrence:
f (1)
f (2)
f (3n)
f (3n + 1)
f (3n + 2)
=
=
=
=
=
34
5
10f (n) + 76 for n > 0
10f (n) − 2 for n > 0
10f (n) + 8 for n > 0
which an instance of the ultimate general recurrence with d = 3
and c = 10.
What is f (19)?
12 of 14
Beyond this lecture. . .
• Read the part of Section 1.3 starting from p.11 for generalizing
the solution to a wider class of problem.
13 of 14
Index (1)
Recall:
Specification of the Josephus Problem
Pattern of the Closed Form Solution to J(n)
Recall: Recurrence Relation and
Closed-Form Solution for J(n)
Another look at the problem
Another look at the closed-form solution
Generalizing the Recurrence Relation for J(n)
Solution to the General Recurrence
Solution to the General Recurrence: Example
Generalizing the Recurrence Relation Further
Solution to the General Recurrence
Solution to the Ultimate General Recurrence: Exercise
Beyond this lecture. . .
14 of 14
© Copyright 2026 Paperzz