Sunday, November 17, 2024
Google search engine
HomeData Modelling & AIAlgorithms | Misc | Question 5

Algorithms | Misc | Question 5

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments