Data Structures & AlgorithmsVery hardGATE CS · DSA

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

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

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

Tracing the vote leaves candidate 3 with counter 1. The candidate is only guaranteed correct when a majority exists; counting shows 3 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