Skip to content

Commit

Permalink
Update 02.Algorithm-Complexity.md
Browse files Browse the repository at this point in the history
  • Loading branch information
itcharge committed May 8, 2024
1 parent 40158e2 commit 8c75fc4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Contents/00.Introduction/02.Algorithm-Complexity.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def algorithm(n):

上述代码中 `cnt = 1` 的时间复杂度为 $O(1)$ 可以忽略不算。`while` 循环体中 $cnt$ 从 $1$ 开始,每循环一次都乘以 $2$。当大于等于 $n$ 时循环结束。变量 $cnt$ 的取值是一个等比数列:$2^0, 2^1, 2^2, …, 2^x$,根据 $2^x = n$,可以得出这段循环体的执行次数为 $\log_2n$,所以这段代码的时间复杂度为 $O(\log_2n)$。

因为 $\log n = k \times \log_2 n$,这里 $k = 3.322$,所以,$\log n$ 与 $\log_2 n$ 的差别比较小。为了方便书写,通常我们将对数时间复杂度写作是 $O(\log n)$。
因为 $\log_2 n = k \times \log_{10} n$,这里 $k \approx 3.322$,是一个常数系数,$\log_2 n$ 与 $\log_{10} n$ 之间差别比较小,可以忽略 $k$。并且 $\log_{10} n$ 也可以简写成 $\log n$,所以为了方便书写,通常我们将对数时间复杂度写作是 $O(\log n)$。

#### 2.3.6 线性对数 $O(n \times \log n)$

Expand Down

0 comments on commit 8c75fc4

Please sign in to comment.