Explanation needed for Boyer-Moore Majority Element, and one of its extensions.

Revision en1, by prac64, 2018-03-27 19:23:17

Hey CodeForces, recently I came accross a problem, finding an element in an array which occurs more than n/3 times, while using constant space and linear time. Now I admit, this is a well known interview problem and plenty of articles exist which cover this, however I have struggled to find one that offers proof of correctness or any explanation.

Please help me understand the correctness.

Article: https://www.geeksforgeeks.org/given-an-array-of-of-size-n-finds-all-the-elements-that-appear-more-than-nk-times/

Basic Idea: Like we do in Boyer-Moore algorithm, however instead of keeping one element and counter, keep 2 , then update them similar to the original algorithm.

Thank you CodeForces!

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English prac64 2018-03-27 19:23:17 789 Initial revision (published)