Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use only C language to do this assignment In this assignment, you have to simulate the Josephus problem. There are n number of prisoners

Please use only C language to do this assignment

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.

Example

For example, if n = 5 and k = 2, then the safe position is 3. Firstly, the person at position 2 is killed,

then person at position 4 is killed, then person at position 1 is killed. Finally, the person at position

5 is killed. So, the person at position 3 survives.

If n = 7 and k = 3, then the safe position is 4. The persons

at positions 3, 6, 2, 7, 5, 1 are killed in

order, and person at position 4 survives.

Input:

n and k

Output:

The position number who

will survive.

Requirement:

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

ISBN: 0262660709, 978-0262660709

Students also viewed these Databases questions