Josephus problem
   HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
and
mathematics Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern mathematics ...
, the Josephus problem (or Josephus permutation) is a theoretical problem related to a certain
counting-out game A counting-out game or counting-out rhyme is a simple method of 'randomly' selecting a person from a group, often used by children for the purpose of playing another game. It usually requires no materials, and is achieved with spoken words or hand ...
. A number of people are standing in a
circle A circle is a shape consisting of all points in a plane that are at a given distance from a given point, the centre. Equivalently, it is the curve traced out by a point that moves in a plane so that its distance from a given point is cons ...
waiting to be executed. Counting begins at a specified point in the circle and proceeds around the circle in a specified direction. After a specified number of people are skipped, the next person is executed. The procedure is repeated with the remaining people, starting with the next person, going in the same direction and skipping the same number of people, until only one person remains, and is freed. The problem—given the number of people, starting point, direction, and number to be skipped—is to choose the position in the initial circle to avoid execution.


History

The problem is named after Flavius Josephus, a Jewish historian living in the 1st century. According to Josephus' account of the siege of Yodfat, he and his 40 soldiers were trapped in a cave by Roman soldiers. They chose suicide over capture, and settled on a serial method of committing suicide by drawing lots. Josephus states that by luck or possibly by the hand of God, he and another man remained until the end and surrendered to the Romans rather than killing themselves. This is the story given in Book 3, Chapter 8, part 7 of Josephus' '' The Jewish War'' ( writing of himself in the third person): The details of the mechanism used in this feat are rather vague. According to James Dowdy and Michael Mays, in 1612 Claude Gaspard Bachet de Méziriac suggested the specific mechanism of arranging the men in a circle and counting by threes to determine the order of elimination. This story has been often repeated and the specific details vary considerably from source to source. For instance, Israel Nathan Herstein and Irving Kaplansky (1974) have Josephus and 39 comrades stand in a circle with every seventh man eliminated. A history of the problem can be found in S. L. Zabell's ''Letter to the editor'' of the '' Fibonacci Quarterly''. Josephus had an accomplice; the problem was then to find the places of the two last remaining survivors (whose conspiracy would ensure their survival). It is alleged that he placed himself and the other man in the 31st and 16th place respectively (for = 3 below).


Variants and generalizations

A medieval version of the Josephus problem involves 15 Turks and 15 Christians aboard a ship in a storm which will sink unless half the passengers are thrown overboard. All 30 stand in a circle and every ninth person is to be tossed into the sea. The Christians need to determine where to stand to ensure that only the Turks are tossed. In other versions the roles of Turks and Christians are interchanged. describe and study a "standard" variant: Determine where the last survivor stands if there are people to start and every second person ( = 2 below) is eliminated. A generalization of this problem is as follows. It is supposed that every th person will be executed from a group of size , in which the th person is the survivor. If there is an addition of people to the circle, then the survivor is in the -th position if this is less than or equal to . If is the smallest value for which , then the survivor is in position .


Solution

In the following, n denotes the number of people in the initial circle, and k denotes the count for each step, that is, k-1 people are skipped and the k-th is executed. The people in the circle are numbered from 1 to n, the starting position being 1 and the counting being inclusive.


''k''=2

The problem is explicitly solved when every second person will be killed (every person kills the person on their left or right), i.e. k=2. (For the more general case k\neq 2, a solution is outlined below.) The solution is expressed recursively. Let f(n) denote the position of the survivor when there are initially people (and k=2). The first time around the circle, all of the even-numbered people die. The second time around the circle, the new 2nd person dies, then the new 4th person, etc.; it is as though there were no first time around the circle. If the initial number of people was even, then the person in position during the second time around the circle was originally in position 2x - 1 (for every choice of ). Let n=2j. The person at f(j) who will now survive was originally in position 2f(j) - 1. This yields the recurrence :f(2j)=2f(j)-1\;. If the initial number of people was odd, then person 1 can be thought of as dying at the end of the first time around the circle. Again, during the second time around the circle, the new 2nd person dies, then the new 4th person, etc. In this case, the person in position was originally in position 2x+1. This yields the recurrence :f(2j+1)=2f(j)+1\;. When the values are tabulated of and f(n) a pattern emerges (, also the leftmost column of blue numbers in the figure above): This suggests that f(n) is an increasing odd sequence that restarts with f(n)=1 whenever the index ''n'' is a power of 2. Therefore, if ''m'' and is chosen so that n=2^m+l and 0\leq l<2^m, then f(n)=2 \cdot l+1. It is clear that values in the table satisfy this equation. Or it can be thought that after people are dead there are only 2^m people and it goes to the 2l+1th person. This person must be the survivor. So f(n)=2l+1. Below, a proof is given by induction. Theorem: If n=2^m+l and 0\leq l<2^m, then f(n) = 2l+1. Proof: The strong induction is used on . The base case n=1 is true. The cases are considered separately when is even and when is odd. If is even, then choose l_1 and m_1 such that n/2 = 2^+l_1 and 0\leq l_1 < 2^. Note that l_1 = l/2. f(n) = 2f(n/2)-1=2((2l_1)+1) - 1=2l+1 is had where the second equality follows from the induction hypothesis. If is odd, then choose l_1 and m_1 such that (n-1)/2 = 2^+l_1 and 0\leq l_1 < 2^. Note that l_1 = (l-1)/2. f(n) = 2f((n-1)/2)+1=2((2l_1)+1) + 1=2l+1 is had where the second equality follows from the induction hypothesis. This completes the proof. can be solved to get an explicit expression for f(n): :f(n) = 2(n-2^)+1 The most elegant form of the answer involves the binary representation of size : f(n) can be obtained by a one-bit left cyclic shift of itself. If is represented in binary as n=1 b_1 b_2 b_3\dots b_m, then the solution is given by f(n)=b_1 b_2 b_3 \dots b_m 1. The proof of this follows from the representation of as 2^m+l or from the above expression for f(n). Implementation: If n denotes the number of people, the safe position is given by the function f(n) = 2l+1, where n=2^m+l and 0\leq l<2^m. Now if the number is represented in binary format, the first bit denotes 2^m and remaining bits will denote . For example, when , its binary representation is n = 1 0 1 0 0 1 2m = 1 0 0 0 0 0 l = 0 1 0 0 1 /** * @param n the number of people standing in the circle * @return the safe position who will survive the execution * f(N) = 2L + 1 where N =2^M + L and 0 <= L < 2^M */ public int getSafePosition(int n)


Bitwise

The easiest way to find the safe position is by using
bitwise operators In computer programming, a bitwise operation operates on a bit string, a bit array or a binary numeral (considered as a bit string) at the level of its individual bits. It is a fast and simple action, basic to the higher-level arithmetic opera ...
. In this approach, shifting the most-significant set bit of n to the least significant bit will return the safe position. Input must be a positive integer. n = 1 0 1 0 0 1 n = 0 1 0 0 1 1 /** * @param n (41) the number of people standing in the circle * @return the safe position who will survive the execution */ public int getSafePosition(int n)


''k''=3

In 1997, Lorenz Halbeisen and Norbert Hungerbühler discovered a closed-form for the case k=3. They showed that there is a certain constant :\alpha \approx 0.8111... that can be computed to arbitrary precision. Given this constant, choose to be the greatest integer such that \operatorname(\alpha \cdot (3/2)^m) \le n (this will be either m^\prime = \operatorname(\log_ n/\alpha) or m^\prime - 1). Then, the final survivor is :f(n) = 3(n - \operatorname(\alpha \cdot (3/2)^m)) + 2 if is rounded up else for all n \ge 5. As an example computation, Halbeisen and Hungerbühler give n = 41, k = 3 (which is actually the original formulation of Josephus' problem). They compute: :m^\prime \approx \operatorname(\log_ 41/0.8111) \approx \operatorname(9.68) = 10 :\operatorname(\alpha \cdot (3/2)^) \approx \operatorname(0.8111 \cdot (3/2)^) = 47 and therefore m = 9 :\operatorname(0.8111 \cdot (3/2)^9) \approx \operatorname(31.18) = 31 (note that this has been rounded down) :f(n) = 3(41 - 31) + 1 = 31 This can be verified by looking at each successive pass on the numbers through : : : : : : : : :


The general case

Dynamic programming Dynamic programming is both a mathematical optimization method and a computer programming method. The method was developed by Richard Bellman in the 1950s and has found applications in numerous fields, from aerospace engineering to economics. ...
is used to solve this problem in the general case by performing the first step and then using the solution of the remaining problem. When the index starts from one, then the person at s shifts from the first person is in position ((s-1)\bmod n)+1, where n is the total number of persons. Let f(n,k) denote the position of the survivor. After the k-th person is killed, a circle of n-1 remains, and the next count is started with the person whose number in the original problem was (k\bmod n)+1. The position of the survivor in the remaining circle would be f(n-1,k) if counting is started at 1; shifting this to account for the fact that the starting point is (k\bmod n)+1 yields the recurrence : f(n,k)=((f(n-1,k)+k-1) \bmod n)+1,\textf(1,k)=1\,, which takes the simpler form : g(n,k)=(g(n-1,k)+k) \bmod n,\textg(1,k)=0 if the positions are numbered from 0 to n-1 instead. This approach has running time O(n), but for small k and large n there is another approach. The second approach also uses dynamic programming but has running time O(k\log n). It is based on considering killing ''k''-th, 2''k''-th, ..., (\lfloor n/k \rfloor k)-th people as one step, then changing the numbering. This improved approach takes the form :g(n,k) = \begin 0 & \text n=1\\ (g(n-1,k)+k) \bmod n & \text 1 < n < k\\ \begin g(n- \left \lfloor \frac \right \rfloor,k)-n \bmod k + n & \text g(n- \left \lfloor \frac \right \rfloor,k)< n \bmod k \\ \lfloor \frac \rfloor & \text g(n- \left \lfloor \frac \right \rfloor,k) \ge n \bmod k \end & \text k \le n\\ \end


References


Citations


Sources

* * * * * * * * *


Further reading

* * * * * * * FUN2010 * * * * *


External links


Josephus Flavius game
(Java Applet) at
cut-the-knot Alexander Bogomolny (January 4, 1948 July 7, 2018) was a Soviet-born Israeli-American mathematician. He was Professor Emeritus of Mathematics at the University of Iowa, and formerly research fellow at the Moscow Institute of Electronics and Math ...
allowing selection of every nth out of 50 (maximum). * * {{YouTube, id=uCsD3ZGzMgE, title=The Josephus Problem - Numberphile
Generalized Josephus Problem
Combinatorics Computational problems Josephus Mathematical problems Permutations