Question

Usin java , Assume N people have decided to elect a leader by arranging themselves in...

Usin java ,

Assume N people have decided to elect a leader by arranging themselves in a circle and eliminating every Mth person around the circle, closing ranks as each person drops out. Find which person will be the last one remaining (with rank 1).

HINT: Assume the input is a circular linked list with N nodes and each node has a number (range 1 to N) associated with it. The head node has number 1 as data.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class leader {
public static int find(int n, int m)
{
if (n == 1)
return 1;
else
return (find(n - 1, m) + m-1) % n + 1;
}
public static void main(String[] args)
{
int n,m;
n= 9;
m = 5;
System.out.println( find(n, m));
}
}
  

*****************************************************************************
PLEASE DO UPVOTE IF THE ANSWER IS HELPFUL AS IT GIVES THE CONFIDENCE TO HELP MORE STUDENTS
*****************************************************************************
Chegg allows me to answer specific no of questions including the sub parts , so please do post the rest of the questions as a separate query as per Chegg Guidelines. Thank you :)
*****************************************************************************

Add a comment
Know the answer?
Add Answer to:
Usin java , Assume N people have decided to elect a leader by arranging themselves in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need different C code then what has been posted here Problem In this assignment, you have...

    Need different C code then what has been posted here Problem 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...

  • Joseph ring 【Problem description】 N people numbered as 1,2...,n sit in a circle in clockwise, and each has only one...

    Joseph ring 【Problem description】 N people numbered as 1,2...,n sit in a circle in clockwise, and each has only one password of positive integer. Firstly a positive integer is arbitrarily selected as the upper limit value m, then numbering off from 1 to m in clockwise is carried out, and the person reporting m will leave the circle and his password will be used as the new m value for the next round of numbering off. This process will carry...

  • n JAVA, students will create a linked list structure that will be used to support a...

    n JAVA, students will create a linked list structure that will be used to support a role playing game. The linked list will represent the main character inventory. The setting is a main character archeologist that is traveling around the jungle in search of an ancient tomb. The user can add items in inventory by priority as they travel around (pickup, buy, find), drop items when their bag is full, and use items (eat, spend, use), view their inventory as...

  • Need help with a number guessing game in java 1) You should store prior guessses in...

    Need help with a number guessing game in java 1) You should store prior guessses in a linked list, and the nodes in the list must follow the order of prior guesses. For example, if the prior guesses are 1000, 2111, 3222 in that order, the nodes must follow the same order 2) You should store the candidate numbers also in a linked list, and the nodes must follow the order of numbers (i.e. from the smallest to the largest)....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT