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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started