Data Structures & AlgorithmsVery hardTCS Digital · Infosys SP

The Boyer–Moore majority vote (candidate/counter, no verification pass) runs on [3, 5, 5, 7, 7, 7, 7, 7, 3]. What candidate and final counter does it return, and is that candidate really a majority (> n/2)?

  1. A. candidate 7, counter 3; no
  2. B. candidate 7, counter 3; yes
  3. C. candidate 7, counter 4; yes
  4. D. candidate 7, counter 5; yes

Correct answer: B. candidate 7, counter 3; yes

Tracing the vote leaves candidate 7 with counter 3. The candidate is only guaranteed correct when a majority exists; counting shows 7 occurs 5 times out of 9, so it is a majority.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic