# Majority voting algorithm, there are n people and m candidates but m is known

The question is long, so I will paraphrase it briefly

Q: There are n people voting to choose the chair of the committee. Each person can vote for one person that has unique id (it is positive integer and vote will be stored in array). Chair will be the one with the most vote. Design algorithm to determine who is the chair and what would be the time complexity? Then if there are m < n candidates for the chair and we know value of m, what would be the algorithm to determine who is the chair and its time complexity?

(Edit: okay so no boyer-moore algorithm)

For the second part, I'm not sure why the fact that I know the value of m makes a difference. The last part of the question sounds like there are more efficient way of solving the problem when m is known.

• Either I don't understand what you are asking at all, or you are way overthinking this. Oct 20 '16 at 3:40
• @WinstonEwert I rechecked the question and the information I need is all in there. Which part do you not understand? It is a problem designed to be challenging. Oct 20 '16 at 3:46
• Counting votes and determining the winner is amongst the most trivial of trivial algorithms. Are you really just figuring out which candidate has the most votes? Why in the world would you even be thinking about Boyer-More? The problem you describe is really really easy, but you are discussing more advanced algorithms, which leaves me utterly unclear about what you are trying to do. Oct 20 '16 at 4:19
• I have no idea what this has to do with Boyer-Moore. Boyer-Moore is a string matching algorithm, there is neither a string nor matching here. There is also no sorting involved, so why is this question tagged with sorting? Oct 20 '16 at 8:46

• Since `m < n` as per the question, The worst case for O(n+m) is O(2n), but of course constants don't matter so it's still O(n). Or in the general case when there's no known relation between n and m: O(max(n, m)).