An array of length with distinct elements is said to be bitonic if there is an index such that is sorted in the non-decreasing order and is sorted in the non-increasing order.
Which ONE of the following represents the best possible asymptotic bound for the worst-case number of comparisons by an algorithm that searches for an element in a bitonic array ?
View worked solution
Answer: D
To find an element in a bitonic array of size , we can design an efficient algorithm using a divide-and-conquer approach in two main steps:
- Find the peak element (index ): The peak element is the maximum element where the array transitions from increasing to decreasing. We can find this peak using a modified binary search:
- Compare the middle element with its neighbors and .
- If , then is the peak.
- If , the peak lies in the right half.
- If , the peak lies in the left half.
- Search for the target element: Once the peak index is identified, the array is split into two sorted subarrays:
- which is sorted in increasing order.
- which is sorted in decreasing order.
Total Complexity:
The total number of comparisons in the worst case is:
Since any comparison-based search in a sorted array of size requires at least comparisons in the worst case, the best possible asymptotic bound for the worst-case number of comparisons is .
Free practice · Your answers on this page are not saved.
