{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

rank trees

# rank trees - The Rank Tree We introduce a data structure...

This preview shows pages 1–2. Sign up to view the full content.

The Rank Tree We introduce a data structure called the rank tree to solve the Josephus problem efficiently. The Josephus Problem n players, numbered 1 to n , are sitting in a circle; starting at player 1, a hot potato is passed; after m passes, the player holding the hop potato is eliminated, the circle closes ranks, and the game continued with the player who was sitting after the eliminated player picking up the hot potato; the last remaining player wins. The Josephus problem arose in the first century A.D in a cave on a mountain in Israel where Jewish zealots were being besieged Roman soldiers. The historian Josephus was among them. To Josephus’s consternation, the zealots voted to enter into a suicide pact rather than surrender to the Romans. He suggested the game that now bears his name. The hot potato was sentence of death to the person next to the one who got the potato. Josephus rigged to get the last lot and convinced the remaining intended victim that the two of them should surrender. That is how we know about this game; in effect, Josephus cheated. Fig. 1 is an example with 5 players and the number of passes being 1. 3 4 5 1 2 3 4 5 1 3 5 1 3 5 3 Figure 1: The Josephus problem: At each step, the darkest circle represents the initial holder and the lightly shaded circle represents the player who received the hot potato (and is eliminated). Passes are made clockwise. What data structure to use? We need a data structure to store the circle of player with following methods: Pass the potato to the next person. Delete the person holding the potato. The Simple Solutions Using a Linked List. The required methods suggest that we can represent the players in a linked list, actually in a circular linked list which is even better considering that players are sitting in a circle. Even though Java does not provide one, we can simulate it easily. If you see the following code, // Return the winner in the Josephus problem. // Linked list implementation.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

rank trees - The Rank Tree We introduce a data structure...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online