Question
In this assignment, you have to simulate the Josephus problem. There are n number of prisoners standing in a circle waiting to be executed. The
In this assignment, you have to simulate the Josephus problem. There are n number of prisoners standing in a circle waiting to be executed. The counting out begins at some point in the circle and proceeds around the circle in a fixed direction. In each step, a certain number of people are skipped and the next person is executed. The elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom. Given the total number of persons n and a number k which indicates that k-1 persons are skipped and kth person is killed in circle. The task is to choose the place in the initial circle so that you are the last one remaining and so survive.
You must use the concept of circular queue while inserting and it should be implemented using circular doubly linked list. You dont need to use front and rear as you are using linked list. Root and last node automatically handle that. Hint: After getting the value of n, generate n numbers (1, 2, 3., , n) and insert into the doubly circular linked list. Then start deleting nodes based on the value of k until the list has only one node remaining.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started