您的位置:首页 > 其它

算法学习之调和级数

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!

从一个简单的查找数组最大值的算法来看,

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,这个公式是一个约等于)。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: