Misra and Gris describe a couple of approaches. I do not quite understand their article, but the key idea is to use a bag.
The original Boyer and Moore algorithm contains a lot of obscure evidence and a discussion of formal verification of the FORTRAN code, but it has a very good start explaining how the majority algorithm works. The key concept starts with the idea that if most of the elements Aand you delete one at a time, a copy Aand a copy of something else, then in the end you will only have copies A. It should then be clear that removing two different elements, none of which is A, can only increase most, whichA. Therefore, it is safe to remove any pairs of objects if they are different. Then this idea can be made concrete. Take the first item from the list and paste it into the box. Take the next item and insert it into the box. If they are the same, let them both sit. If the new one is different, throw it along with the item out of the box. Repeat until all items are in the box or basket. Since only one element is allowed in a field, it can be represented very effectively as a pair (item type, count).
, n/k, , , , . , k, . ? w > n/k, w-1 > (n-k)/k. , , k-1 , !
: , , k-1 . , k ( k-1), ), , , . ""? , , ! , , O (log k) O (n log k). , ( , O (k log k)), , . , , , , ( ). , . , , , - O (nk).