调和级数及时间复杂度相关
rong_nian
·
·
个人记录
令 H(x) = \sum\limits_{i=1}^x \frac{1}{i} 为调和级数.
H(x) \approx \ln(x)
H(x) = \ln(x + 1) + \gamma$ $(\gamma = \lim\limits_{x\to\infty}\int_1^n\frac{1}{\lfloor x\rfloor}-\frac{1}{x}dx\approx 0.57721566490153286060651209)
证明 :
\begin{aligned}
\sum_{i=1}^n\dfrac{1}{i} &= \sum_{i=1}^n\int_i^{i+1}\dfrac{1}{\lfloor x\rfloor}dx \\ &= \int_1^{n+1} \frac{1}{x} + \frac{1}{\lfloor x \rfloor} - \frac{1}{x} dx \\ &= \int_1^{n+1} \frac{1}{x}dx + \int_1^{n+1}\frac{1}{\lfloor x \rfloor} - \frac{1}{x} dx \\ &= \ln(n+1) + \gamma = H(n)
\end{aligned}
算数级数:与末项平方同阶
T(n) = 1+2+\cdots+n = n(n+1)/2 = O(n^2)
幂方级数:比幂次高出一阶
T_2(n) = 1^2 + 2^2 + 3^2 + \cdots + n^2 = n(n+1)(2n+1)/6 = O(n^3)
T_3(n) = 1^3 + 2^3 + 3^3 + \cdots + n^3 = n^2(n+1)^2/4 = O(n^4)
T_4(n) = 1^4 + 2^4 + 3^4 + \cdots + n^4 = n(n+1)(2n+1)(3n^2 + 3n -1)/30 = O(n^5)
几何级数(a > 1):与末项同阶
T_a(n) = a^0 + a^1 + \cdots + a^n = (a^{n+1} -1)/(a - 1) = O(a^n)
1 + 2 + 4 + \cdots + 2^n = 2^{n+1} - 1 = O(2^{n+1}) = O(2^n)
收敛级数
1/1/2 + 1/2/3 + 1/3/4 + \cdots + 1/(n-1)/n = 1 - 1/n = O(1)
1 + 1/2^2 + … + 1/n^2 < 1 + 1/2^2 + \cdots = \pi^2/6 = O(1)
1/3 + 1/7 + 1/8 + 1/15 + 1/24 + 1/26 + 1/31 + 1/35 + \cdots = 1 = O(1)
可能未必收敛,但是长度有限
调和级数 :
H(n) = 1 + 1/2 + 1/3 + \cdots + 1/n = O(\log(n))
对数级数 :
\log(1) + \log(2) + \log(3) + \cdots + \log(n) = \log(n!) = O(n\log(n))