Overview of the solution for Josephus problem where every third person is eliminated, followed by a solution for the general case (arbitrary "q" where every q'th person is eliminated).
In addition a short discussion of interesting problem deriving from Josephus Problem.
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
General Solution for Josephus Problem
1. A General Solution to Josephus Problem
Yoav Francis
July 2007
Topics in Number Theory, 2007/2
COMAS – College of Management – Academic Studies, Rishon Lezion, Israel
Overview and Additional Problems
2. Motivation
• Given 𝑞 ∈ ℕ, find 𝐽𝑜𝑠𝑒𝑝ℎ𝑢𝑠 𝑞(𝑛), where 𝑛
denotes the number of people in the initial circle.
• Let us first consider the case in which 𝑞 = 3.
4. A General Method for 𝐽𝑜𝑠𝑒𝑝ℎ𝑢𝑠3(𝑛)
For a group of 𝑛 people, each time we iterate on a person, we can provide
him with a new number. In such a scenario – the numbers 1,2 would become
𝑛 + 1, 𝑛 + 2. The number 3 would then be killed. 4,5 would become 𝑛 + 3, 𝑛 +
4. 6 would be killed, and so on.
Finally, 3𝑘 + 1, 3𝑘 + 2 would become 𝑛 + 2𝑘 + 1, 𝑛 + 2𝑘 + 2, and 3𝑘 + 3 would
be killed and so on.
Eventually the person denoted as 3𝑛 will be the sole survivor.
Illustration for 𝑛 = 10, 𝑞 = 3:
5. A General Method for 𝐽𝑜𝑠𝑒𝑝ℎ𝑢𝑠3(𝑛)
• The 𝑘 𝑡ℎ person to be killed is denoted 3𝑘 (Example: the 10th person is
numbered “30”, the 9th is numbered “27” and so on)
• We can find out who is the survivor if we find the original number of the
person numbered 3𝑛 (let us mark 𝑁 = 3𝑛)
• If 𝑁 > 𝑛 then the person numbered 𝑁 necessarily had a previous number,
which we can find in the following manner:
• 𝑁 = 𝑛 + 2𝑘 + 1 or 𝑁 = 𝑛 + 2𝑘 + 2 (Similarly to how we found the next number of 3𝑘 + 1 and
3𝑘 + 2 in the previous slide)
• Thus 𝑘 =
𝑁−𝑛−1
2
. The previous number of the person was 3𝑘 + 1 or 3𝑘 + 2
– meaning, it was 3𝑘 + 𝑁 − 𝑛 − 2𝑘 = 𝑘 + 𝑁 − 𝑛 (using 𝑁 − 𝑛 − 2𝑘 = 1)
6. A General Method for 𝐽𝑜𝑠𝑒𝑝ℎ𝑢𝑠3(𝑛)
We have received an algorithm for 𝐽𝑜𝑠𝑒𝑝ℎ𝑢𝑠3(𝑛):
7. A General Method for 𝐽𝑜𝑠𝑒𝑝ℎ𝑢𝑠3(𝑛)
Let us note that this can be somewhat improved. The algorithm is not
recursive, neither has a “closed” shape – but still allows us to compute the
answer rather quickly for a large 𝑛.
Luckily, we can improve it.
• Let us define 𝐷 = 3𝑛 + 1 − 𝑁 and use it instead of 𝑁.
• This change matches numbering from 3𝑛 to 1 instead of from 1 to 3𝑛.
• This yields the following:
8. A General Method for 𝐽𝑜𝑠𝑒𝑝ℎ𝑢𝑠3(𝑛)
We can now write the algorithm in the following manner:
This is a much simpler form as 𝑛 enters the computation in a simple manner.
9. The General Algorithm for Josephus Problem
In a matter of fact, we can use the same justifications we used to show that
the survivor for 𝐽𝑜𝑠𝑒𝑝ℎ𝑢𝑠 𝑞(𝑛) (where every 𝑞 𝑡ℎ
person is killed) is computed in
the following way:
This is the general algorithm. Let us note that for 𝑞 = 2 we’d get in every
phase 𝐷 = 2𝐷, so for the case of 𝑞 = 2 we get:
𝐽𝑜𝑠𝑒𝑝ℎ𝑢𝑠2 𝑛 = 2 ⋅ 𝑛 − 2 log2 𝑛
+ 1
10. The General Algorithm for Josephus Problem
We can attempt to bring the algorithm to a “nicer” form.
It cannot be brought to a closed form (but for the case of 𝑞 = 2), due to the
“ceiling” function that we perform on every phase.
However – we can still tidy-up the algorithm. Let us recursively define:
These numbers do not have a “nice” form but for 𝑞 = 2, but if we agree to
accept the expression 𝐷 𝑛
(𝑞)
as a “known expression” – then the solution for the
general case of the Josephus problem would be:
(Where 𝑘 is the smallest one for which the following holds: Dk
(𝑞)
> 𝑞 − 1 ⋅ 𝑛 )
11. Additional Problems Derived From
Josephus Problem
Finding 𝐼 𝑛 the second-to-last person remaining in Josephus problem
(For example, if we want to find the last 2 people standing).
Let us denote 𝑛 = 2 𝑚 + 1 and get:
12. Additional Problems Derived From
Josephus Problem
Another problem: Josephus finds himself in the position 𝑗 (1 ≤ 𝑗 ≤ 𝑛).
Given that he can choose the “skip factor”(𝑞), which 𝑞 should he
choose so he stays alive?
Let us define 𝐿 𝑛 = 𝐿𝐶𝑀(1,2,3, … , 𝑛) and assume that 𝑛 > 2. By
Bertrand’s Postulate there exists a prime number
𝑛
2
< 𝑝 < 𝑛. We can
also assume that 𝑗 >
𝑛
2
.
We’d want to choose a q so the following holds:
• 𝑞 ≡ 1 𝑚𝑜𝑑
𝐿 𝑛
𝑝
and:
• 𝑞 ≡ 𝑗 + 1 − 𝑛 (𝑚𝑜𝑑 𝑝)
13. Additional Problems Derived From
Josephus Problem
Now, the people who would be removed (“killed”) are:
• 1,2,….,n−p, j+1, j+2,….,n, n−p+1,…..j−1
The 𝑗 𝑡ℎ
position would not be killed (we may get 𝑞 ≥ 𝑛 but that is still
valid for the problem)
Example:
• 𝑛 = 10, 𝑝 = 7. Josephus got 𝑗 = 6 and will decide: 𝑞 = 361
(This holds for the 2 requirements of 𝑞).
• LCM(1,….,10) = 2520