Question: Problem 1. 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
Problem 1.
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). If there is no majority element, your program should indicate it. And then run these algorithms with four given sample sets(Majex1, 2, 3, 4) of input files and measure execution time for each case. Method 1 (O(N2) algorithm: Write a Java program to have two loops and keep track of maximum count for all different elements. If maximum count becomes greater than N/2 then break the loops and return the element having maximum count. If maximum count doesnt become more than N/2 then majority element doesnt exist
--JAVA---
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
