Search for a majority element in an array with hidden elements

I am having trouble resolving this general issue with a slight twist:

According to n fields with one hidden number inside and a verification procedure that decides whether two fields contain the same or different numbers, determine if there is a number that is present in most boxes, i.e. are there more than n / 2 mailboxes with the same hidden number in O (n log n) time.

I know the Moore Voting algorithm, but this problem seems a bit different.

+4
source share
1 answer

You can use Moore's voting algorithm as it is (executed in O (n) time and O (1) space).

Taken from Moore 's own website :

.

, . , 0.

e:

  • 0, e, 1.
  • 0, , e .

, , .

:

, .

, , , .

e, .

, , , . n/2, .

+6

All Articles