Question: This question is from Algorithms, 4th Edition by Sedgewick and Wayne. In the Josephus problem from antiquity, N people are in dire straits and agree

This question is from Algorithms, 4th Edition by Sedgewick and Wayne. 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. Learn more about the problem here: The Josephus Problem - Numberphile Implement the function josephus(n,m) in queue.c. You MUST use your Queue to solve this problem. The function takes to integers as input. The integers are n and m. Your program will return an array with the people in the order in which people are eliminated. Josephus will sit in whatever value is in the last index of the array. You must use your Queue from the previous part to solve this problem. Simplification Assumptions: You may assume the user will always give two positive numbers. Your array will always have n elements. The main program already prints the array for you. Here are some example executions. Test 01 % ./main Select Option from list. 0.) Run All Tests 1.) Test New Queue 2.) Test Enqueue 3.) Test Front 4.) Test isEmpty 5.) Test Dequeue 6.) Run Randomized Tests 7.) Josephus Puzzle Enter Number of test to run: 7 Enter Number of People (N): 7 Enter Person to Eliminate (M): 2 Order Eliminated: 1 3 5 0 4 2 6 Test 02 % ./main Select Option from list. 0.) Run All Tests 1.) Test New Queue 2.) Test Enqueue 3.) Test Front 4.) Test isEmpty 5.) Test Dequeue 6.) Run Randomized Tests 7.) Josephus Puzzle Enter Number of test to run: 7 Enter Number of People (N): 7 Enter Person to Eliminate (M): 3 Order Eliminated: 2 5 1 6 4 0 3 Test 03 % ./main Select Option from list. 0.) Run All Tests 1.) Test New Queue 2.) Test Enqueue 3.) Test Front 4.) Test isEmpty 5.) Test Dequeue 6.) Run Randomized Tests 7.) Josephus Puzzle Enter Number of test to run: 7 Enter Number of People (N): 10 Enter Person to Eliminate (M): 2 Order Eliminated: 1 3 5 7 9 2 6 0 8 4 Test 04 % ./main Select Option from list. 0.) Run All Tests 1.) Test New Queue 2.) Test Enqueue 3.) Test Front 4.) Test isEmpty 5.) Test Dequeue 6.) Run Randomized Tests 7.) Josephus Puzzle Enter Number of test to run: 7 Enter Number of People (N): 100 Enter Person to Eliminate (M): 7 Order Eliminated: 6 13 20 27 34 41 48 55 62 69 76 83 90 97 4 12 21 29 37 45 53 61 70 78 86 94 2 11 22 31 40 50 59 68 79 88 98 8 18 30 42 52 64 74 85 96 9 23 35 47 60 73 87 0 15 28 44 58 75 91 5 24 39 57 77 93 14 33 54 72 95 17 43 66 89 16 46 71 1 32 65 99 36 80 10 56 3 51 7 67 26 92 82 81 84 25 63 19 38 49 Test 05 % ./main Select Option from list. 0.) Run All Tests 1.) Test New Queue 2.) Test Enqueue 3.) Test Front 4.) Test isEmpty 5.) Test Dequeue 6.) Run Randomized Tests 7.) Josephus Puzzle Enter Number of test to run: 7 Enter Number of People (N): 98 Enter Person to Eliminate (M): 12 Order Eliminated: 11 23 35 47 59 71 83 95 9 22 36 49 62 75 88 3 17 31 45 60 74 89 5 20 37 52 67 82 0 16 33 51 68 85 4 24 41 58 78 96 18 39 57 79 1 25 44 66 90 13 38 63 86 12 40 65 92 21 50 77 8 42 72 6 34 73 10 48 84 27 64 7 54 94 46 93 53 2 61 26 81 55 28 97 80 70 69 76 91 19 43 29 15 32 30 14 87 56

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!