Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose you have an unsorted array A[1..n] of elements. You can only do equality tests on the elements (e.g. they are large GIFs). In

  

Suppose you have an unsorted array A[1..n] of elements. You can only do equality tests on the elements (e.g. they are large GIFs). In particular this means that you cannot sort the array. You want to find (if it exists) a majority element, i.e., an element that appears more than half the time. For example in [a, b, a] the majority element is a, but [a,b,c] and [a, a, b, c] have no majority element. Straightforward approach of checking if A[i] is a majority element for all i = 1,...,n will have run-time in O(n) which is too slow. Consider the following approach to finding a majority element: recursively find the majority element y in the first half of the array and the majority element z in the second half of the array, and combine results of recursive calls into the answer to the problem. (a) Prove that if x is a majority element in A then it has to be a majority element in the first half of the array or the second half of the array (or both). (b) Using observation of part (a) give a divide-and-conquer algorithm to find a majority element, that runs in time O(nlogn). Detailed pseudocode is required. Be sure to argue correctness and analyze the run time. If given array has no majority element, return FAIL.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Human Resource Management Text And Cases

Authors: Tom Redman, Adrian Wilkinson

4th Edition

0273757822, 9780273757825

More Books

Students also viewed these Programming questions

Question

Specific statement of a businesss purpose and direction

Answered: 1 week ago

Question

What is the likelihood function for a logistic regression model?

Answered: 1 week ago

Question

T F Obsessional thinking helps relieve anxiety. (p. 190)

Answered: 1 week ago