局部最小值的算法

这是一种基于分治的做法
基于二分的对于数组的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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值