Really simple, elegant solution to a hard problem. There are some alternatives that are arguably better in ways, but none are nearly as simple to comprehend
The Boyer–Moore majority algorithm [1] which allows you to find the majority element (if one exists) in an unsorted array in linear time and constant space.
..and its generalization [2], which finds the (at most) k elements whose frequency is more than 1/(k+1) in the unsorted stream (k=1 being the majority algorithm in [1].)
Comments (491) 209 threads
Earlier commentsReally simple, elegant solution to a hard problem. There are some alternatives that are arguably better in ways, but none are nearly as simple to comprehend
[1] https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_v...
[2] https://www.cs.bgu.ac.il/~dinitz/Course/SS-12/Karp-frequent-...
I really like backtracing algorithms used to solve huge graphs without actually visiting all nodes. Pretty elegant IMO.
All comments shown.
Couldn't load more comments. Check your connection and try again.