Peak finding
来源:互联网 发布:淘宝代购敲诈应对技巧 编辑:程序博客网 时间:2024/04/30 07:01
1-Dimention peak-finding first.
For a n-length array arr, if exist arr[i-1] <= arr[i] >= a[i+1], i belong to [0,n-1], we consider i is a peak of this array.
If we divide the array in the middle for one comparation and recursively run.
The T(n) = T(n/2) + 2. T(n) = O(logn)
2-Dimention peak-finding.
Here’s one idea, when there’s plenty of numbers and we just want to find one of them that is suit for our needs, what we should do to optimize the algo is partition and pruning.
Now we will use the following algo as an example.
Assume there’s one m times n array. And our task is to find the peak for which the adjacent number is not great than.
Clear right.
Then we choose the middle column and find the max which we denote as g of this column subarray. Comparing this max with its left and right number.
If no greater than g, the g is a peak.
Otherwise, recursively run ther above step in the left half or right half which is determind by the which side has the greater value.
It take T(n) = T(n/2) + m and T(n) = mlogn = O(nlogn)
Prove the correctness:
Here we find the max value of mid column array, g.
If g is a peak, finish the program, right.
Otherwise h is greater than g, that means h is greater than any number of mid column right. Now we find the max value in the same column as h, using k to denote. No doublt k is greater than the number on its right side.
So the peak is k if there’s no column at the right side or the right number is not greater than k. Or the peak is not k, then we redo the above step to do the same work for k as we did for g.
Finally you can find, there’s only two case, not touch the left most column, but we find a peak, touch the left most column but the max of this column is a peak.
The right side proving is almost the same.
Proved.
3-D peak-finding.
Personally speaking, 3-D is similar to 2-D, but find the maximun of the middle plane, and the following steps are the same as 2-D.
- Peak Finding
- Peak finding
- 一维Peak finding 算法
- Codility-Peak
- Density Peak
- finding work
- Finding Software
- Finding Nemo
- Finding Nemo
- Finding Nemo
- VPS finding
- 【Python Challenge-5】peak
- [LeetCode] Find Peak Element
- Find Peak Element
- Leetcode:Find Peak Element
- Find Peak Element
- Find Peak Element
- Find Peak Element
- 面试挫折录-第1集
- C++:基础写一函数,使输入的一个字符串按反序存放,在主函数中输入输出反序后的字符串。:
- 继承关系总结
- linux 下查看系统资源和负载,以及性能监控
- Jasperreports的XSD翻译
- Peak finding
- OkHttp中的拦截器使用--翻译自官方文档
- pyton文件读写
- apt-get无法获取kubelet kubeadm kubectl包
- HBase详细介绍
- 解决:Cmake配置CGAL1.62.0出错
- 【C++面向对象】C++中成员函数的const属性
- Android 固定头部的ListView以及下拉刷新(附源码)
- 字体的应用