Election to choose new leader

Assignment Help Basic Computer Science
Reference no: EM131171557

A community of N pirates has recently conducted an election to choose their new leader. All pirates vote, and any pirate may run as a candidate. There is no preferential system, each pirate simply writes the number of their preffered leader on the ballot paper. If a single pirate gets more than 50% of the votes, then that pirate is declared the new leader. If no pirate gets more than 50% of the votes, then the old leader is retained. N pirates have voted, and their choices have been collected in an array A. Your task is to determine whether there will be a new leader and, if there will, who the new leader will be. For example, given the array 4, 4, 7, 1, 7, 7, 2, 7, 7 pirate 7 has 5 votes out of 9, and becomes the new leader, whereas given the array 4, 4, 7, 1, 4, 7, 2, 4 pirate 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 possibly have more than 50% of the votes. To find a possible winner in the array, A, create a second array, 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 the array B, stopping when the array has less than 2 elements. If a  possible winner has been found, scan through the array and count the number of votes received by the possible winner. If the possible winner has more than N/2 votes, print the possible winner out as the winner. If no possible winner is 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, T 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 describe an alternative algorithm.

(e) What are the (Big-Oh) time and space1 complexities of your new algorithm? Compare this to the previous algorithm and explain under what circumstances would you use one algorithm or the other?

Reference no: EM131171557

Questions Cloud

How important are stakeholder relationship : Organizations must ensure a proper balance in differing stakeholder values by exercising good corporate citizenship. Companies should first take inventory of why they are vested in the company and how well they align or misalign with the company's..
Group policy on windows servers : 1. What are some of the advantages of using Group Policy? What are some of the things that can be managed with it?
Evaluate strategies for contract negotiation : Synthesize knowledge and concepts from advanced practice nursing with supporting disciplines as a foundation for APN/specialty nurse practitioner practice that is culturally competent and population-specific
Audience visualize how the security team functions : Create a 4- to 5-slide narrated presentation in response to the request from the CEO. Include an organizational chart to help the audience visualize how the security team functions. Include detailed speaker notes or transcription of narration.
Election to choose new leader : A community of N pirates has recently conducted an election to choose their new leader. All pirates vote, and any pirate may run as a candidate. There is no preferential system, each pirate simply writes the number of their preffered leader on the..
The economic argument for protectionism : The economic argument for protectionism is that it preserves jobs, protects a nation's political security, discourages dependency on other countries, and:
Reflect the chicanao latino experience in the local society : Write an outline for persuasive speech (choose any essay that reflect the topics listed below and write an outline on). The topic for the persuasive speech outline must reflect the Chicana/o Latino Experience in the local and global society.
Petty cash register available to record all outflow of funds : Which one of the following is a key report that a new business owner should be prepared to generate? Which of the following accounts requires both a cash register and a petty cash register available to record all outflow of funds? A small business ow..
How do you plan to deliver training: face-to-face or online : Imagine that you must make a proposal to your supervisor to create a training workshop for new hires in your field to help them acclimate to their jobs. Write a 500-word essay explaining your proposal to a colleague. Include a description of the p..

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Multinomial distribution and the chi-squared test

Consider dealing a hand of 3 cards from a well shuffled standard deck of playing cards. Let X1 be the number of eights in the hand; let X2 be the number of nines in the hand; and let X3 be the number of cards in the hand that are neither eights nor n..

  Optimal value of the objective function

Find the optimal value of the objective function for the following problem by only inspecting its dual. (Do not solve the dual by the simplex method)

  Function of cryptographic hashing

Which of the following is NOT a function of cryptographic hashing:

  Easyphp and mysql setup

Install EasyPHP and MySQL and take a screen shot that shows the MySQL prompt on your screen. (Note: You must include the screen shot which shows that MySQL is installed on your computer as part of your assignment. An installation guide to aid the ..

  The activity life cycle of an android application

the activity life cycle of an android application

  Define a class client which has attributes name

Your menu should allow you to add new clients, accept payments from clients using the client's name, make loans, look up a client's balance, remove a client,

  Transform the query into a query on fragments

Transform the query into a query on fragments.

  Business continuity plans and disaster recovery

In recent years, organizations have witnessed the impact of having effective and non-effective business continuity plans and disaster recovery plans. In today's environment, with significant potential natural disasters, terrorist threats, and othe..

  Demonstrations illustrating the types of storefronts

Store Front (www.storefront.net) is a vendor of e-business software. At its site, the company provides demonstrations illustrating the types of storefronts that it can create for shoppers. The site also provides demonstrations of how the company's..

  How do you define a constructor in java

How do you call Inherited Class Members in Java? Provide an example.

  A flow chart and a pseudocode

A flow chart and a pseudocode

  Cost of a planned renovation and expansion of facility

Then negative cash flow in year 5 reflects the cost of a planned renovation and expansion of the facility. Finally, in year 10, Garmen estimates some recovery of its investment at the close of the lease, and consequently a higher-than-usual cash f..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd