Loading section...
Heavy Hitters: Boyer-Moore Voting in O(1) Space
Concepts: pyBoyerMoore, pyMajorityVote, pyHeavyHitters
The majority vote problem: given an array, find the element that appears more than n/2 times. The Counter solution is O(n) time and O(n) space. Boyer-Moore voting is O(n) time and O(1) space — no dict, no Counter, no memory allocation proportional to cardinality. It is one of the most elegant algorithms in computer science. The generalization — finding all elements that appear more than n/k times — requires O(k) space and appears in data engineering as 'find all dominant event types in a stream' or 'find all partition keys that represent more than 10% of data.' Boyer-Moore: Majority Element (n/2) Generalization: Elements Appearing More Than n/k Times There can be at most k-1 elements that appear more than n/k times (since k elements each appearing more than n/k times would exceed n total).