Question: ( 2 0 pts . ) Majority Element. An array A [ 0 , dots, n - 1 ] is said to have a majority
pts Majority Element. An array dots, is said to have a majority element if more than half
of its entries are the same. Given an array, the task is to design an efficient algorithm to tell whether the array
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 so there can be no comparisons of the form is
Think of the array elements as image files, say. However you can answer questions of the form: is
in constant time.
a Show that if is a majority element in the array then is a majority element in the first half of the array
or in the second half of the array.
b Show how to check in time if a candidate element is indeed a majority element.
c Put these observation together to design a divideandconquer algorithm whose running time is
Hint: Use the master theorem to analyze its running time.
d We will now design a lineartime algorithm. Here's another divideandconquer approach:
Pair up the elements of A arbitrarily, to get pairs. If is odd, we keep the singleton unpaired
element but only to break a potential tie; that is this element can't be used to overrule a majority.
Look at each pair: if the two elements are different, discard both of them; if they are the same,
keep just one of them.
Let be the elements left after this procedure. Show that has at most ~~ elements, and that if
has a majority element, then has the same majority element.
e Use parts d and b to design an algorithm for this problem with running time.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
