This commit is contained in:
krahets
2023-11-09 05:13:48 +08:00
parent 9701430089
commit 0105644232
83 changed files with 516 additions and 509 deletions

View File

@@ -7,7 +7,7 @@ icon: material/timer-sand
<div class="center-table" markdown>
![复杂度分析](../assets/covers/chapter_complexity_analysis.jpg){ width="600" }
![复杂度分析](../assets/covers/chapter_complexity_analysis.jpg){ class="cover-image" }
</div>

View File

@@ -184,7 +184,7 @@ comments: true
图 2-1 展示了该求和函数的流程框图。
![求和函数的流程框图](iteration_and_recursion.assets/iteration.png)
![求和函数的流程框图](iteration_and_recursion.assets/iteration.png){ class="animation-figure" }
<p align="center"> 图 2-1 &nbsp; 求和函数的流程框图 </p>
@@ -823,7 +823,7 @@ comments: true
图 2-2 给出了该嵌套循环的流程框图。
![嵌套循环的流程框图](iteration_and_recursion.assets/nested_iteration.png)
![嵌套循环的流程框图](iteration_and_recursion.assets/nested_iteration.png){ class="animation-figure" }
<p align="center"> 图 2-2 &nbsp; 嵌套循环的流程框图 </p>
@@ -1028,7 +1028,7 @@ comments: true
图 2-3 展示了该函数的递归过程。
![求和函数的递归过程](iteration_and_recursion.assets/recursion_sum.png)
![求和函数的递归过程](iteration_and_recursion.assets/recursion_sum.png){ class="animation-figure" }
<p align="center"> 图 2-3 &nbsp; 求和函数的递归过程 </p>
@@ -1051,7 +1051,7 @@ comments: true
如图 2-4 所示,在触发终止条件前,同时存在 $n$ 个未返回的递归函数,**递归深度为 $n$** 。
![递归调用深度](iteration_and_recursion.assets/recursion_sum_depth.png)
![递归调用深度](iteration_and_recursion.assets/recursion_sum_depth.png){ class="animation-figure" }
<p align="center"> 图 2-4 &nbsp; 递归调用深度 </p>
@@ -1227,7 +1227,7 @@ comments: true
- **普通递归**:求和操作是在“归”的过程中执行的,每层返回后都要再执行一次求和操作。
- **尾递归**:求和操作是在“递”的过程中执行的,“归”的过程只需层层返回。
![尾递归过程](iteration_and_recursion.assets/tail_recursion_sum.png)
![尾递归过程](iteration_and_recursion.assets/tail_recursion_sum.png){ class="animation-figure" }
<p align="center"> 图 2-5 &nbsp; 尾递归过程 </p>
@@ -1432,7 +1432,7 @@ comments: true
观察以上代码,我们在函数内递归调用了两个函数,**这意味着从一个调用产生了两个调用分支**。如图 2-6 所示,这样不断递归调用下去,最终将产生一个层数为 $n$ 的「递归树 recursion tree」。
![斐波那契数列的递归树](iteration_and_recursion.assets/recursion_tree.png)
![斐波那契数列的递归树](iteration_and_recursion.assets/recursion_tree.png){ class="animation-figure" }
<p align="center"> 图 2-6 &nbsp; 斐波那契数列的递归树 </p>

View File

@@ -24,7 +24,7 @@ comments: true
在分析一段程序的空间复杂度时,**我们通常统计暂存数据、栈帧空间和输出数据三部分**。
![算法使用的相关空间](space_complexity.assets/space_types.png)
![算法使用的相关空间](space_complexity.assets/space_types.png){ class="animation-figure" }
<p align="center"> 图 2-15 &nbsp; 算法使用的相关空间 </p>
@@ -717,7 +717,7 @@ O(1) < O(\log n) < O(n) < O(n^2) < O(2^n) \newline
\end{aligned}
$$
![常见的空间复杂度类型](space_complexity.assets/space_complexity_common_types.png)
![常见的空间复杂度类型](space_complexity.assets/space_complexity_common_types.png){ class="animation-figure" }
<p align="center"> 图 2-16 &nbsp; 常见的空间复杂度类型 </p>
@@ -1463,7 +1463,7 @@ $$
}
```
![递归函数产生的线性阶空间复杂度](space_complexity.assets/space_complexity_recursive_linear.png)
![递归函数产生的线性阶空间复杂度](space_complexity.assets/space_complexity_recursive_linear.png){ class="animation-figure" }
<p align="center"> 图 2-17 &nbsp; 递归函数产生的线性阶空间复杂度 </p>
@@ -1842,7 +1842,7 @@ $$
}
```
![递归函数产生的平方阶空间复杂度](space_complexity.assets/space_complexity_recursive_quadratic.png)
![递归函数产生的平方阶空间复杂度](space_complexity.assets/space_complexity_recursive_quadratic.png){ class="animation-figure" }
<p align="center"> 图 2-18 &nbsp; 递归函数产生的平方阶空间复杂度 </p>
@@ -2015,7 +2015,7 @@ $$
}
```
![满二叉树产生的指数阶空间复杂度](space_complexity.assets/space_complexity_exponential.png)
![满二叉树产生的指数阶空间复杂度](space_complexity.assets/space_complexity_exponential.png){ class="animation-figure" }
<p align="center"> 图 2-19 &nbsp; 满二叉树产生的指数阶空间复杂度 </p>

View File

@@ -462,7 +462,7 @@ $$
- 算法 `B` 中的打印操作需要循环 $n$ 次,算法运行时间随着 $n$ 增大呈线性增长。此算法的时间复杂度被称为“线性阶”。
- 算法 `C` 中的打印操作需要循环 $1000000$ 次,虽然运行时间很长,但它与输入数据大小 $n$ 无关。因此 `C` 的时间复杂度和 `A` 相同,仍为“常数阶”。
![算法 A、B 和 C 的时间增长趋势](time_complexity.assets/time_complexity_simple_example.png)
![算法 A、B 和 C 的时间增长趋势](time_complexity.assets/time_complexity_simple_example.png){ class="animation-figure" }
<p align="center"> 图 2-7 &nbsp; 算法 A、B 和 C 的时间增长趋势 </p>
@@ -661,7 +661,7 @@ $T(n)$ 是一次函数,说明其运行时间的增长趋势是线性的,因
如图 2-8 所示,计算渐近上界就是寻找一个函数 $f(n)$ ,使得当 $n$ 趋向于无穷大时,$T(n)$ 和 $f(n)$ 处于相同的增长级别,仅相差一个常数项 $c$ 的倍数。
![函数的渐近上界](time_complexity.assets/asymptotic_upper_bound.png)
![函数的渐近上界](time_complexity.assets/asymptotic_upper_bound.png){ class="animation-figure" }
<p align="center"> 图 2-8 &nbsp; 函数的渐近上界 </p>
@@ -950,7 +950,7 @@ O(1) < O(\log n) < O(n) < O(n \log n) < O(n^2) < O(2^n) < O(n!) \newline
\end{aligned}
$$
![常见的时间复杂度类型](time_complexity.assets/time_complexity_common_types.png)
![常见的时间复杂度类型](time_complexity.assets/time_complexity_common_types.png){ class="animation-figure" }
<p align="center"> 图 2-9 &nbsp; 常见的时间复杂度类型 </p>
@@ -1642,7 +1642,7 @@ $$
图 2-10 对比了常数阶、线性阶和平方阶三种时间复杂度。
![常数阶、线性阶和平方阶的时间复杂度](time_complexity.assets/time_complexity_constant_linear_quadratic.png)
![常数阶、线性阶和平方阶的时间复杂度](time_complexity.assets/time_complexity_constant_linear_quadratic.png){ class="animation-figure" }
<p align="center"> 图 2-10 &nbsp; 常数阶、线性阶和平方阶的时间复杂度 </p>
@@ -2148,7 +2148,7 @@ $$
}
```
![指数阶的时间复杂度](time_complexity.assets/time_complexity_exponential.png)
![指数阶的时间复杂度](time_complexity.assets/time_complexity_exponential.png){ class="animation-figure" }
<p align="center"> 图 2-11 &nbsp; 指数阶的时间复杂度 </p>
@@ -2460,7 +2460,7 @@ $$
}
```
![对数阶的时间复杂度](time_complexity.assets/time_complexity_logarithmic.png)
![对数阶的时间复杂度](time_complexity.assets/time_complexity_logarithmic.png){ class="animation-figure" }
<p align="center"> 图 2-12 &nbsp; 对数阶的时间复杂度 </p>
@@ -2790,7 +2790,7 @@ $$
图 2-13 展示了线性对数阶的生成方式。二叉树的每一层的操作总数都为 $n$ ,树共有 $\log_2 n + 1$ 层,因此时间复杂度为 $O(n \log n)$ 。
![线性对数阶的时间复杂度](time_complexity.assets/time_complexity_logarithmic_linear.png)
![线性对数阶的时间复杂度](time_complexity.assets/time_complexity_logarithmic_linear.png){ class="animation-figure" }
<p align="center"> 图 2-13 &nbsp; 线性对数阶的时间复杂度 </p>
@@ -2994,7 +2994,7 @@ $$
}
```
![阶乘阶的时间复杂度](time_complexity.assets/time_complexity_factorial.png)
![阶乘阶的时间复杂度](time_complexity.assets/time_complexity_factorial.png){ class="animation-figure" }
<p align="center"> 图 2-14 &nbsp; 阶乘阶的时间复杂度 </p>