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
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