What is the solution to the Josephus Problem?

What is the solution to the Josephus Problem?

Josephus (according to the story) was among other things an accomplished mathematician; so he instantly figured out where he ought to sit in order to be the last to go. But when the time came, instead of killing himself he joined the Roman side. The solution is for Josephus to stand in the twenty-fourth position.

Which linked list have the last node of the list pointing to the first node *?

circular linked list
A circular linked list is a linked list in which last node always point to the first node i.e. last node contains the address of the first node.

Is there a solution to the problem of Josephus?

So, we found a solution to the problem of Josephus, working in O ( n) operations. This formula can also be found analytically. Again here we assume 0-indexing. After we delete the first number, we have n − 1 numbers left. When we repeat the procedure, we will start with the number that had originally the index k mod m .

Why is the Josephus problem important to computer science?

The Josephus problem is pretty famous in the world of Computer Science since it involves the concept of Recursion. Recursion is a concept in Computer Science where we make use of the same line/snippet of code repeatedly to find a solution.

What is the recursive structure of the Josephus problem?

The problem has following recursive structure. After the first person (kth from beginning) is killed, n-1 persons are left. So we call josephus(n – 1, k) to get the position with n-1 persons. But the position returned by josephus(n – 1, k) will consider the position starting from k%n + 1.

Which is the correct formula for Josephus ( n, k )?

josephus(n, k) = (josephus(n – 1, k) + k-1) % n + 1 josephus(1, k) = 1. After the first person (kth from beginning) is killed, n-1 persons are left. So we call josephus(n – 1, k) to get the position with n-1 persons.