CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

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

A
(n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
(log n)
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
(log2n)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
(1)
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is B (log n)
Consider any array of n elements which stored integers in sorted order, A[1], A[2],...A[n]. If we want to search an element x with the help of binary search then in expected case comparison is not greater than log(n + 1). But if integral appears n/2 times in an array and array already sorted then it take (1) times for consecutive locations. So total no. of comparison is not greater than (log n) time.

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Logarithmic Inequalities
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon