Question: design and describe an O(nlogn)-time algorithm Suppose we are given an n-element sequence S such that each element in S represents a different vote in
design and describe an O(nlogn)-time algorithm
Suppose we are given an n-element sequence S such that each element in S represents a different vote in an election, where each vote is given as an integer representing the ID of the chosen candidate (we dont know in advance how many different IDs there will be and we dont know the range of the ID values). Without making any assumptions about who is running or even how many candidates there are, design and describe an O(nlogn)-time algorithm to output which ID wins the election S represents, assuming the candidate with the most votes wins.
Example: {2, 4, 543567, 2, 3, 543, 4, 543567, 543567}, ID 543567 wins
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
