Question: Please write program in C++ Please write program in C++ A majority element in an array, A, of size N is an element that appears

Please write program in C++Please write program in C++Please write program in C++ A majority elementPlease write program in C++

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 this. Design three different algorithms and write them in Java or other programming language. And then run these algorithms with four given sample sets(Majex1, 2, 3, 4) of input files and measure execution time for each case. a) Method 1 (O(N2) algorithm: Write a 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 doesn't become more than N/2 then majority element doesn't exist b) Method 2 (O(NlogN) algorithm using a divided-and-conquer method. The algorithm begins by splitting the array in half repeatedly and calling itself on each half. When we get down to single elements that single element is returned as the majority of its (1-element) array. At every other level, it will get return values from its two recursive calls

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!