Question: Consider the voting problem from Exercise C-12.35, but now suppose that we know the number k < n of candidates running, even though the integer
Consider the voting problem from Exercise C-12.35, but now suppose that we know the number k < n of candidates running, even though the integer IDs for those candidates can be arbitrarily large. Describe an O(nlogk)-time algorithm for determining who wins the election.
In Exercise
Suppose we are given an n-element sequence S such that each element in S represents a different vote for president, where each vote is given as an integer representing a particular candidate, yet the integers may be arbitrarily large (even if the number of candidates is not). Design an O(nlogn)-time algorithm to see who wins the election S represents, assuming the candidate with the most votes wins.
Step by Step Solution
3.47 Rating (173 Votes )
There are 3 Steps involved in it
In this case we can store candidate IDs in a balanced search tree such as an AVL tree or ... View full answer
Get step-by-step solutions from verified subject matter experts
