Question: Please help me with this algorithm! I can't seem to understand how to do it. Thank you so much in advanced! Implement Majority-Element finding using

Please help me with this algorithm! I can't seem to understand how to do it. Thank you so much in advanced!

Implement Majority-Element finding using Algorithm V

Input: array of N positive integers - size of the problem is N

Output: 1) majority element (M.E.) element occurring more than N/2 times (order of elements doesnt matter) IF THE MAJORITY ELEMENT EXISTS

2) -1 if the majority element does not exist in the array

Input should be read into array of integers: int[]

The code should work on that array, without re-formatting the data e.g. into a linked list or any other data structure

The algorithm should have O(N) time complexity

Use of any Java built-in functions/classes is NOT allowed

With the exception of functions from Scanner, System.in and System.out (or equivalent) for input/output

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!