Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CREATIVE PROBLEM 1.3.37 JOSEPHUS PROBLEM (see http://mathworld.wolfram.com/JosephusProblem.html) In the Josephus problem from antiquity, N people are in dire straits and agree to the following strategy

CREATIVE PROBLEM 1.3.37 JOSEPHUS PROBLEM (see http://mathworld.wolfram.com/JosephusProblem.html) In the Josephus problem from antiquity, N people are in dire straits and agree to the following strategy to reduce the population. They arrange themselves in a circle (at positions numbered from 0 to N???1) and proceed around the circle, eliminating every Mth person until only one person is left. Legend has it that Josephus figured out where to sit to avoid being eliminated. Write a Queue client Josephus.java that takes M and N from the command line and prints out the order in which people are eliminated (and thus would show Josephus where to sit in the circle). /************************************************************************* * Compilation: javac Josephus.java * Execution: java Josephus M N * Dependencies: Queue.java * * Solves the Josephus problem. * * % java Josephus 2 7 * 1 3 5 0 4 2 6 * *************************************************************************/Josephus.java IS SORTED ALPHABETICALLY...REWRITE IT CORRECTLY SO THAT IT COMPILES AND SOLVES THE JOSEPHUS PROBLEM

_____________________________________________________________

 // initialize the queue
{
{
{
 
} 
}
}
 
for (int i = 0; i < M-1; i++)
for (int i = 0; i < N; i++)
 
int M = Integer.parseInt(args[0]);
int N = Integer.parseInt(args[1]);
 
public class Josephus 
public static void main(String[] args) 
 
q.enqueue(i);
q.enqueue(q.dequeue());
 
Queue q = new Queue();
 
StdOut.print(q.dequeue() + " ");
StdOut.println();
 
while (!q.isEmpty()) 

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

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

=+ What level of support do they have from their constituents?

Answered: 1 week ago

Question

Q.No.1 Explain Large scale map ? Q.No.2 Explain small scale map ?

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago