in Algorithms retagged by
1,064 views
0 votes
0 votes
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) (log*n)
(D) (1)
in Algorithms retagged by
1.1k views

1 Answer

0 votes
0 votes

The Best way to find out whether an integer appears more than n/2 times in a sorted array(Ascending Order) of n integers, would be binary search approach.

1. The First occurrence of an element can be found out in O(log(n)) time using divide and conquer technique,lets say it is i.

2. The Last occurrence of an element can be found out in O(log(n)) time using divide and conquer technique,lets say it is j.

3. Now number of occurrence of that element(count) is (j-i+1). Overall time complexity = log n +log n +1 = O(logn).

Hence answer is Option B

Answer:

Related questions