Open In App
Related Articles

Algorithms | Misc | Question 5

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The minimum number of comparisons required to determine if an integer appears more than n/2 times in a sorted array of n integers is 

(A)

θ(n)

(B)

θ(logn)

(C)

θ(nlogn)

(D)

θ(1)



Answer: (B)

Explanation:

whenever there exists an element which is present in the array : more than n/2 times, then definitely it will be present at the middle index position; in addition to that it will also be present at anyone of the neighbourhood indices namely i−1 and i+1 
No matter how we push that stream of More than n/2 times of elements of same value around the Sorted Array, it is bound to be present at the middle index + atleast anyone of its neighbourhood once we got the element which should have occurred more that n/2 times we count its total occurences in O(log⁡n) time.



Quiz of this Question
Please comment below if you find anything wrong in the above post

Last Updated : 10 Jul, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments