Can anyone think of a linear time algorithm for determining a majority element in a list of elements? The algorithm should use O(1) space.
If n is the s
I think it is possible, using Boyer-Moore, though not directly.
As Matthew stated, Boyer-Moore only guarantees to find the majority element for a slightly different definition of majority, called strict majority. Your definition is slightly weaker, but not by much.
The 1. and 2. steps are straight-forward. The 3. works because by removing instances of the failed candidates, we are now looking for a strict majority element. The 4. is optional, and only to be used if there is a possibility that no majority element exists.