majority-1.0: Boyer-Moore Majority Vote Algorithm

Portabilityportable (Haskell 2010)
Stabilityprovisional
Maintainerniswegmann@gmail.com

Algorithms.Majority

Description

 

Synopsis

Documentation

majority :: Eq a => [a] -> Maybe aSource

O(length xs), Determines if there in a list of votes xs is a candidate that has more than half of the votes, and if so, returns that canditate.

E.g. applying majority on the string "AAACCBBCCCBCC" yields Just 'C', since 'C' has 7 out of 13 votes.