Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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?

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91924159
  • Price:- $50

Guranteed 36 Hours Delivery, In Price:- $50

Have any Question?


Related Questions in Computer Engineering

Tests can determine with some degree of accuracy whether a

Tests can determine, with some degree of accuracy, whether a subject indeed has the disease for which s/he is being tested. For instance, a new screening procedure for heart disease was tested on 100 patients with heart ...

Are us executives paid too much particularly compared to

Are U.S. Executives paid too much particularly compared to the average worker in their organization?

Short papercritically analyze current european and united

Short Paper Critically analyze current European and United States industry standards or recommendations for any Information Technology (IT) area or subarea (e.g., intrusion detection, data recovery, data retention, intru ...

A chemistry student needsnbsp600 mlnbspof carbon

A chemistry student needs 60.0 mL of carbon tetrachloride for an experiment. By consulting the  CRC Handbook of Chemistry and Physics , the student discovers that the density of carbon tetrachloride is 1.59 g.cm^-3. Calc ...

Give an example of a binary relation which is not

Give an example of a binary relation which is not transitive, and then give an example of a binary relation which is reflexive and transitive but not connected.

We have bottles of milk that have a mean of 20 oz and

We have bottles of milk that have a mean of 20 oz and standard deviation of 0.02. What is the probability that a bottle would have a mean of more than 20.3 oz?

Question what is stp what is rstp and what methods does

Question : What is STP, what is RSTP, and what methods does Cisco provide to make these two methods work better as networks grow? The response must be typed, single spaced, must be in times new roman font (size 12) and m ...

System analysis and design1 explain the difference between

System Analysis and Design 1) Explain the difference between too much feedback and too little feedback and provide a scenario for each one (two scenarios are needed - one for a lot of feedback and one for too much) and w ...

Q1 the market for apples is perfectly competitive say a

Q1. The market for apples is perfectly competitive. Say a typical firm has a marginal cost function of MC(q) = 2q. (1) The optimal quantity of apples to produce is 10 for the typical firm. How much revenue does the firm ...

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As