The minimum number of comparisons required to determine if an integer appears more than times in a sorted array of integers is
View worked solution
Answer: B
To determine if any integer appears more than times in a sorted array of size , we can use the following approach:
- Identify the Candidate: If an element appears more than times in a sorted array, it must occupy the middle position of the array. Let this candidate element be .
- Find the Boundaries: To check if actually appears more than times, we need to find its first occurrence (index ) and its last occurrence (index ) in the array.
- Binary Search: Since the array is sorted, we can find both and using binary search. Each binary search takes comparisons.
- Verify the Count: If , then is the majority element. Otherwise, no such element exists.
Since binary search is optimal for searching in a sorted array, the minimum number of comparisons required in the worst case is .
Free practice · Your answers on this page are not saved.
