这是一种基于分治的做法
基于二分的对于数组的O(lgn)级别的算法
Find local minima in an array
You are given an array Arr[1 .. n] with the special property that Arr[1] ≥ Arr[2] and Arr[n − 1] ≤ Arr[n]. We say that an element Arr[x] is a local minimum if it is less than or equal to both its neighbors. Derive an algorithm in O(log n)
For example in the array 9,6,2,14,5,7,4 – 2 is a local minima as it is smaller than its left and right number 6 and 14. Similarly 5 is another local minima as it is between 14 and 7, both larger than 5. You need to find any one of the local minima.
解决方法
如果数组的元素不能保证互不相同,不可能在O(lgn)时间内解决这个问题。因为如果这个数组全是1,那么必须要遍历数组中的所有元素才有可能确定不存在,至少是O(n)
同时
如果数组中的元素不相同。
如果只有一个元素,那么这个元素就是minuma
如果两个元素,那么其中较小的就是minuma
如果中间的元素不满足,那么就考虑较小的一部分
那么我们考察鞍点的性质;如果a<b&l