Question
Let A(1..n] be an array. A is said to have a majority element if more than half of its elements are the same. Given an
Let A(1..n] be an array. A is said to have a majority element if more than half of its elements are the same. Given an array Aj1.n], the task is to design an efficient algorithm to tell whether the has a majority element, and if so, to find that element. The elements of the array are not necessarily from some ordered domain (like the integers), and hence there can be no comparison of the form "is A[i] > A[j]" or "is A[i]
Give an O(nlgn)-time divide-and-conquer algorithm for the above problem/task. (Hint. Split the array A into two subarrays of half the size. Does knowing the majority elements of the two subarrays help figuring out the majority element for A?)
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