Question: roblem Description: In computer science and mathematics, the Josephus problem is a theoretical problem related to a certain counting-out game. Here's the basic, if not


roblem Description: In computer science and mathematics, the Josephus problem is a theoretical problem related to a certain counting-out game. Here's the basic, if not somewhat gruesome, story People are standing in a circle waiting to be executed. A number is selected at random (the skip count). Counting begins with person number 1 and proceeds around the circle. The person at the skip count is executed. Yikes! The procedure is repeated with the remaining people, starting with the next person, going in the same direction and skipping to the same number person, until only one person remains, and is freed Graduation is coming up, our future is bright, so we want to be that last person! Given the number of people in the group and number to be skipped, we want to choose the position in the initial circle to avoid execution. This is probably best illustrated with an example. If there are 10 people (numbered 1 through 10) and the group has decided to eliminate every 3rd (skip count 3), you would expect the sequence to go as follows: 1st round: 1 2 (3) 4 5 (6) 7 8 (9) 10. Persons 3, 6, and 9 were "eliminated". .2nd round: 1 (2) 45 (7) 8 10. Persons 2 and 7 were "eliminated. . 3rd round: (1) 45 (8) 10. Persons 1 and 8 were "eliminated". . 4th round: 4 (5) 10. Person 5 was "eliminated". . 5th round: 4 (10). Person 10 was "eliminated" Therefore, the last remaining person will be #4. That's where we want to be Use a class that implements java.util.Queue> (for example LinkedList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
