Question: from java and algorithm classes: 5.33 A majority element in an array A of size N is an element that appears more than N/2 times

from java and algorithm classes: 5.33 A majority element in an array A of size N is an element that appears more than N/2 times (thus there is at most one each element). For example, the array

3,3,4,2,4,4,2,4,4 has a majority element (4), whereas the array 3,3,4,2,4,4,2,4 does not. Give an algorithm to find a majority element if one exists, or reports that one does not.What is the running time of your algorithms?

(hint: there is an O (N) solution).

5.33 you dont need to write code that runs in O (N) time, but you do need to properly state the runtime of your code.

the method is called majorityElement

the starting part

public static boolean majorityElement(int[] a) {

return Math.random() < 0.5;

}

}

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!