![]() |
VOOZH | about |
Given an array arr[] of integers which is initially strictly increasing and then strictly decreasing, the task is to find the bitonic point, that is the maximum value in the array.
Note: Bitonic Point is a point in bitonic sequence before which elements are strictly increasing and after which elements are strictly decreasing.
Examples:
Input: arr[] = [1, 2, 4, 5, 7, 8, 3]
Output: 8
Explanation: 8 is the maximum element in the array.Input: arr[] = [10, 20, 30, 40, 50]
Output: 50
Explanation: 50 is the maximum element in the array.Input: arr[] = [120, 100, 80, 20, 0]
Output: 120
Explanation: 120 is the maximum element in the array.
Table of Content
A simple approach is to traverse the array and keep track of maximum element. Finally return the maximum element.
8
We can optimize the maximum element searching by using Binary Search where we find the mid element and then decide whether to stop or to go to left half or right half. How do we decide in this case.
- If the mid element is greater than both of its adjacent elements, then mid is the maximum.
- If the mid element is smaller than its next element then we should try to search on the right half of the array. So, update low = mid + 1.
- If the mid element is greater than the next element, then we should try to search on the left half. So, update high = mid - 1.
8