算法学习之调和级数
2015-12-04 11:13
423 查看
Harmonic numbers(调和级数,参考链接:About Harmonic numbers)常用于算法分析,它的最大特征是:随着n取值的增大,相邻的两个Harmonic numbers的差将变小,且它不收敛,趋向于无穷,只是递增的趋势会越来越慢。原文如下:
A remarkable characteristic of harmonic numbers is that, even though as n gets
large and the difference between consecutive harmonic numbers gets arbitrarily small (
), the
series does not converge!
从一个简单的查找数组最大值的算法来看,
Thus, the running time of the above Program,
,
is a function not only of the number of elements in the array, n, but also of the actual array values,
.
即,它的时间开销不但和数组大长度n相关,也和数组元素的序列有关。其中,最好的情况是,数组降序排列,最坏的情况是数组升序排列。此外,需要关注的是,一个随机排列的数组,查找最大值的平均时间开销,即T(average)。
参考Average Running times,T(average) = t1 + t2 * n + t3 * ( H(n) - 1),即与Harmonic numbers相关。
而 H(n-1) = In(n) (约等于对数加Euler constant,这个公式是一个约等于)。
A remarkable characteristic of harmonic numbers is that, even though as n gets
large and the difference between consecutive harmonic numbers gets arbitrarily small (
), the
series does not converge!
从一个简单的查找数组最大值的算法来看,
unsigned int FindMaximum(unsigned int a[], unsigned int n) { unsigned int result = a[0]; for (int i = 1; i < n; ++i) if ( result < a[i]) result = a[i]; return result; }
Thus, the running time of the above Program,
,
is a function not only of the number of elements in the array, n, but also of the actual array values,
.
即,它的时间开销不但和数组大长度n相关,也和数组元素的序列有关。其中,最好的情况是,数组降序排列,最坏的情况是数组升序排列。此外,需要关注的是,一个随机排列的数组,查找最大值的平均时间开销,即T(average)。
参考Average Running times,T(average) = t1 + t2 * n + t3 * ( H(n) - 1),即与Harmonic numbers相关。
而 H(n-1) = In(n) (约等于对数加Euler constant,这个公式是一个约等于)。
相关文章推荐
- 九度OJ 1356:孩子们的游戏(圆圈中最后剩下的数) (约瑟夫环)
- android(4)(短信发送器)
- CRS-4124: Oracle High Availability Services startup failed.
- 滑动切换activity
- mysql 实验
- python读取word表格内容(1)
- 九度OJ 1356:孩子们的游戏(圆圈中最后剩下的数) (约瑟夫环)
- 观察者模式
- Day_4数组
- NYOJ 306 走迷宫
- UITextField文字缩进
- fastJson
- Android学习之 WebView使用小结
- 关于Safari里quickOn绑定click事件闪屏问题的解决方案
- 写给小白的JavaScript引擎指南
- java(算法1)二分法
- 兔子cms电脑版自动切换跳转到wap手机版的方法
- 运行Perl程序
- 关于HTTP协议状态码的问题
- Codeception API testing