Suppose that the votes of n people for different candidates (where there can be more than two candidates) for a particular office are the elements of a sequence. A person wins the election if this person receives a majority of the votes.
Pare 562
a) Devise a divide-and-conquer algorithm that deter- mines whether a candidate received a majority and, if so, determine who this candidate is. [Hint:
Assume that n is even and split the sequence of votes into two sequences, each with
b) Use the master theorem to give a big-O estimate for the number of comparisons needed by the algorithm you devised in part (a).
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Discrete Mathematics and Its Applications ( 8th International Edition ) ISBN:9781260091991
- Algebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:Cengage