05 Jun A community of N pirates has recently conducted
Question
A community of N pirates has recently conducted an election to choose their new leader. All piratesvote, and any pirate may run as a candidate. There is no preferential system, each pirate simplywrites the number of their preffered leader on the ballot paper. If a single pirate gets more than50% of the votes, then that pirate is declared the new leader. If no pirate gets more than 50% of thevotes, then the old leader is retained.N pirates have voted, and their choices have been collected in an array A. Your task is to determinewhether there will be a new leader and, if there will, who the new leader will be. For example, giventhe array4, 4, 7, 1, 7, 7, 2, 7, 7pirate 7 has 5 votes out of 9, and becomes the new leader, whereas given the array4, 4, 7, 1, 4, 7, 2, 4pirate 4 has 4 votes out of 8 but doesn’t manage to get over 50% so the old leader is retained.Your team has proposed the following algorithm to determine which, if any, candidate wins:First, a possible winner must be found. This possible winner the only candidate that could possiblyhave more than 50% of the votes. To find a possible winner in the array, A, create a secondarray, B. Compare A[0] and A[1]. If they are equal, put one of them in B; otherwise do nothing.Then compare A[2] and A[3]. Again if they are equal, add one of these to B; otherwise do nothing.Continue like this until the entire array A has been used. Recursively find a possible winner on thearray B, stopping when the array has less than 2 elements. If a possible winner has been found, scanthrough the array and count the number of votes received by the possible winner. If the possiblewinner has more than N/2 votes, print the possible winner out as the winner. If no possible winneris found, or the possible winner does not have enough votes, print that the old leader is retained.(a) What is the worst case space complexity for this algorithm (consider the array(s) B only)?Explain your reasoning.(b) Give the O, ? and, if possible, ? time complexities for this algorithm. Explain your reasoning.(c) Why does this algorithm work? You may assume the array size is even for all function calls.(d) What problem occurs when the array size is odd? Propose a fix for this problem, or describean alternative algorithm.(e) What are the (Big-Oh) time and space1complexities of your new algorithm? Compare this tothe previous algorithm and explain under what circumstances would you use one algorithm orthe other?
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.
