There are candidates and total votes. A majority occurs when there is a candidate with votes greater than
Claim 1
- If there is a majority, removing two votes from different candidates causes the majority to remain
Proof
- If a candidate has votes and one vote is removed from them, then the proportion of votes they will have is , so they will still have the majority
Claim 2
- A majority may be established by removing votes from different candidates
- What if you start off with exactly two candidates with the same number of votes?
Proof
- Assume a majority can’t be established by removing votes from different candidates
- Let be the candidate with the most votes or one of multiple candidates who have the same and most number of votes
- Choose any other candidate
Brute Force:
- For each element in the array
- Initialize a counter
- For each element in the array
- If
- ++
- If half the number of elements
- break
- If
- Element is the majority element
Moore’s Voting Algorithm:
- c := 0, representing candidate majority counter
- x := 1 to store index position
- For each element
- If c == 0
- x = i
- c++
- Else If x == i
- c++
- Else
- c—
- If c == 0
- c = 0
- Check the candidate majority is indeed a majority element
- For each element i
- If x == i
- c++
- If x == i
- If c > n/2
- x is a majority element