diff --git a/chapter_appendix/contribution.md b/chapter_appendix/contribution.md index ebe5b8765..26452ad8f 100644 --- a/chapter_appendix/contribution.md +++ b/chapter_appendix/contribution.md @@ -14,7 +14,7 @@ comments: true 然而在本开源书中,内容更迭的时间被缩短至数日甚至几个小时。 -## 16.2.1   内容微调 +### 1.   内容微调 如图 16-1 所示,每个页面的右上角都有“编辑图标”。您可以按照以下步骤修改文本或代码。 @@ -28,7 +28,7 @@ comments: true 图片无法直接修改,需要通过新建 [Issue](https://github.com/krahets/hello-algo/issues) 或评论留言来描述问题,我们会尽快重新绘制并替换图片。 -## 16.2.2   内容创作 +### 2.   内容创作 如果您有兴趣参与此开源项目,包括将代码翻译成其他编程语言、扩展文章内容等,那么需要实施以下 Pull Request 工作流程。 @@ -38,7 +38,7 @@ comments: true 4. 将本地所做更改 Commit ,然后 Push 至远程仓库。 5. 刷新仓库网页,点击“Create pull request”按钮即可发起拉取请求。 -## 16.2.3   Docker 部署 +### 3.   Docker 部署 执行以下 Docker 脚本,稍等片刻,即可在网页 `http://localhost:8000` 访问本项目。 diff --git a/chapter_appendix/installation.md b/chapter_appendix/installation.md index 195ee32d2..949441595 100644 --- a/chapter_appendix/installation.md +++ b/chapter_appendix/installation.md @@ -4,56 +4,56 @@ comments: true # 16.1   编程环境安装 -## 16.1.1   VSCode +### 1.   VSCode 本书推荐使用开源轻量的 VSCode 作为本地 IDE ,下载并安装 [VSCode](https://code.visualstudio.com/) 。 -## 16.1.2   Java 环境 +### 2.   Java 环境 1. 下载并安装 [OpenJDK](https://jdk.java.net/18/)(版本需满足 > JDK 9)。 2. 在 VSCode 的插件市场中搜索 `java` ,安装 Extension Pack for Java 。 -## 16.1.3   C/C++ 环境 +### 3.   C/C++ 环境 1. Windows 系统需要安装 [MinGW](https://sourceforge.net/projects/mingw-w64/files/)([配置教程](https://blog.csdn.net/qq_33698226/article/details/129031241)),MacOS 自带 Clang 无须安装。 2. 在 VSCode 的插件市场中搜索 `c++` ,安装 C/C++ Extension Pack 。 3. (可选)打开 Settings 页面,搜索 `Clang_format_fallback Style` 代码格式化选项,设置为 `{ BasedOnStyle: Microsoft, BreakBeforeBraces: Attach }` 。 -## 16.1.4   Python 环境 +### 4.   Python 环境 1. 下载并安装 [Miniconda3](https://docs.conda.io/en/latest/miniconda.html) 。 2. 在 VSCode 的插件市场中搜索 `python` ,安装 Python Extension Pack 。 3. (可选)在命令行输入 `pip install black` ,安装代码格式化工具。 -## 16.1.5   Go 环境 +### 5.   Go 环境 1. 下载并安装 [go](https://go.dev/dl/) 。 2. 在 VSCode 的插件市场中搜索 `go` ,安装 Go 。 3. 快捷键 `Ctrl + Shift + P` 呼出命令栏,输入 go ,选择 `Go: Install/Update Tools` ,全部勾选并安装即可。 -## 16.1.6   JavaScript 环境 +### 6.   JavaScript 环境 1. 下载并安装 [node.js](https://nodejs.org/en/) 。 2. 在 VSCode 的插件市场中搜索 `javascript` ,安装 JavaScript (ES6) code snippets 。 3. (可选)在 VSCode 的插件市场中搜索 `Prettier` ,安装代码格式化工具。 -## 16.1.7   C# 环境 +### 7.   C# 环境 1. 下载并安装 [.Net 6.0](https://dotnet.microsoft.com/en-us/download) 。 2. 在 VSCode 的插件市场中搜索 `C# Dev Kit` ,安装 C# Dev Kit ([配置教程](https://code.visualstudio.com/docs/csharp/get-started))。 3. 也可使用 Visual Studio([安装教程](https://learn.microsoft.com/zh-cn/visualstudio/install/install-visual-studio?view=vs-2022))。 -## 16.1.8   Swift 环境 +### 8.   Swift 环境 1. 下载并安装 [Swift](https://www.swift.org/download/)。 2. 在 VSCode 的插件市场中搜索 `swift` ,安装 [Swift for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang)。 -## 16.1.9   Dart 环境 +### 9.   Dart 环境 1. 下载并安装 [Dart](https://dart.dev/get-dart) 。 2. 在 VSCode 的插件市场中搜索 `dart` ,安装 [Dart](https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code) 。 -## 16.1.10   Rust 环境 +### 10.   Rust 环境 1. 下载并安装 [Rust](https://www.rust-lang.org/tools/install)。 2. 在 VSCode 的插件市场中搜索 `rust` ,安装 [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)。 diff --git a/chapter_backtracking/backtracking_algorithm.md b/chapter_backtracking/backtracking_algorithm.md index e92284493..3e6117197 100644 --- a/chapter_backtracking/backtracking_algorithm.md +++ b/chapter_backtracking/backtracking_algorithm.md @@ -1667,6 +1667,8 @@ comments: true 为了更清晰地分析算法问题,我们总结一下回溯算法中常用术语的含义,并对照例题三给出对应示例。 +

表 13-1   常见的回溯算法术语

+
| 名词 | 定义 | 例题三 | diff --git a/chapter_backtracking/permutations_problem.md b/chapter_backtracking/permutations_problem.md index ea4d0d2eb..ae9f784b6 100644 --- a/chapter_backtracking/permutations_problem.md +++ b/chapter_backtracking/permutations_problem.md @@ -6,9 +6,9 @@ comments: true 全排列问题是回溯算法的一个典型应用。它的定义是在给定一个集合(如一个数组或字符串)的情况下,找出这个集合中元素的所有可能的排列。 -表 13-1 列举了几个示例数据,包括输入数组和对应的所有排列。 +表 13-2 列举了几个示例数据,包括输入数组和对应的所有排列。 -

表 13-1   数组与链表的效率对比

+

表 13-2   数组与链表的效率对比

diff --git a/chapter_computational_complexity/time_complexity.md b/chapter_computational_complexity/time_complexity.md index f063701bd..096f62580 100755 --- a/chapter_computational_complexity/time_complexity.md +++ b/chapter_computational_complexity/time_complexity.md @@ -643,7 +643,7 @@ $T(n)$ 是一次函数,说明其运行时间的增长趋势是线性的,因 1. **忽略 $T(n)$ 中的常数项**。因为它们都与 $n$ 无关,所以对时间复杂度不产生影响。 2. **省略所有系数**。例如,循环 $2n$ 次、$5n + 1$ 次等,都可以简化记为 $n$ 次,因为 $n$ 前面的系数对时间复杂度没有影响。 -3. **循环嵌套时使用乘法**。总操作数量等于外层循环和内层循环操作数量之积,每一层循环依然可以分别套用第 `1.` 点和第 `2.` 点的技巧。、 +3. **循环嵌套时使用乘法**。总操作数量等于外层循环和内层循环操作数量之积,每一层循环依然可以分别套用第 `1.` 点和第 `2.` 点的技巧。 给定一个函数,我们可以用上述技巧来统计操作数量。 diff --git a/chapter_data_structure/number_encoding.md b/chapter_data_structure/number_encoding.md index 4ffcfcbc9..823380155 100644 --- a/chapter_data_structure/number_encoding.md +++ b/chapter_data_structure/number_encoding.md @@ -18,7 +18,7 @@ comments: true - **反码**:正数的反码与其原码相同,负数的反码是对其原码除符号位外的所有位取反。 - **补码**:正数的补码与其原码相同,负数的补码是在其反码的基础上加 $1$ 。 -图 3-4 展示了原吗、反码和补码之间的转换方法。 +图 3-4 展示了原码、反码和补码之间的转换方法。 ![原码、反码与补码之间的相互转换](number_encoding.assets/1s_2s_complement.png) diff --git a/chapter_greedy/greedy_algorithm.md b/chapter_greedy/greedy_algorithm.md index 3d13ea083..35f9aec62 100644 --- a/chapter_greedy/greedy_algorithm.md +++ b/chapter_greedy/greedy_algorithm.md @@ -5,7 +5,7 @@ status: new # 15.1   贪心算法 -贪心算法是一种常见的解决优化问题的算法,其基本思想是在问题的每个决策阶段,都选择当前看起来最优的选择,即贪心地做出局部最优的决策,以期望获得全局最优解。贪心算法简洁且高效,在许多实际问题中都有着广泛的应用。 +「贪心算法 greedy algorithm」是一种常见的解决优化问题的算法,其基本思想是在问题的每个决策阶段,都选择当前看起来最优的选择,即贪心地做出局部最优的决策,以期望获得全局最优解。贪心算法简洁且高效,在许多实际问题中都有着广泛的应用。 贪心算法和动态规划都常用于解决优化问题。它们之间存在一些相似之处,比如都依赖最优子结构性质,但工作原理是不同的。 diff --git a/chapter_searching/binary_search.md b/chapter_searching/binary_search.md index 19d40d226..cbd575d41 100755 --- a/chapter_searching/binary_search.md +++ b/chapter_searching/binary_search.md @@ -27,7 +27,7 @@ comments: true 若数组不包含目标元素,搜索区间最终会缩小为空。此时返回 $-1$ 。 === "<1>" - ![binary_search_step1](binary_search.assets/binary_search_step1.png) + ![二分查找流程](binary_search.assets/binary_search_step1.png) === "<2>" ![binary_search_step2](binary_search.assets/binary_search_step2.png) @@ -47,7 +47,7 @@ comments: true === "<7>" ![binary_search_step7](binary_search.assets/binary_search_step7.png) -

图 10-2   binary_search_step1

+

图 10-2   二分查找流程

值得注意的是,由于 $i$ 和 $j$ 都是 `int` 类型,**因此 $i + j$ 可能会超出 `int` 类型的取值范围**。为了避免大数越界,我们通常采用公式 $m = \lfloor {i + (j - i) / 2} \rfloor$ 来计算中点。 @@ -332,9 +332,9 @@ comments: true } ``` -时间复杂度为 $O(\log n)$ 。每轮缩小一半区间,因此二分循环次数为 $\log_2 n$ 。 +**时间复杂度 $O(\log n)$** :在二分循环中,区间每轮缩小一半,循环次数为 $\log_2 n$ 。 -空间复杂度为 $O(1)$ 。指针 $i$ 和 $j$ 使用常数大小空间。 +**空间复杂度 $O(1)$** :指针 $i$ 和 $j$ 使用常数大小空间。 ## 10.1.1   区间表示方法 diff --git a/chapter_tree/avl_tree.md b/chapter_tree/avl_tree.md index 397697201..9ae464086 100644 --- a/chapter_tree/avl_tree.md +++ b/chapter_tree/avl_tree.md @@ -26,7 +26,7 @@ AVL 树既是二叉搜索树也是平衡二叉树,同时满足这两类二叉 ### 1.   节点高度 -在操作 AVL 树时,我们需要获取节点的高度,因此需要为 AVL 树的节点类添加 `height` 变量。 +由于 AVL 树的相关操作需要获取节点高度,因此我们需要为节点类添加 `height` 变量。 === "Java" diff --git a/chapter_tree/binary_search_tree.md b/chapter_tree/binary_search_tree.md index 28f8c3f51..0dc88e977 100755 --- a/chapter_tree/binary_search_tree.md +++ b/chapter_tree/binary_search_tree.md @@ -738,15 +738,15 @@ comments: true 如图 7-19 所示,当待删除节点的度为 $0$ 时,表示该节点是叶节点,可以直接删除。 -![在二叉搜索树中删除节点(度为 0)](binary_search_tree.assets/bst_remove_case1.png) +![在二叉搜索树中删除节点(度为 0 )](binary_search_tree.assets/bst_remove_case1.png) -

图 7-19   在二叉搜索树中删除节点(度为 0)

+

图 7-19   在二叉搜索树中删除节点(度为 0 )

如图 7-20 所示,当待删除节点的度为 $1$ 时,将待删除节点替换为其子节点即可。 -![在二叉搜索树中删除节点(度为 1)](binary_search_tree.assets/bst_remove_case2.png) +![在二叉搜索树中删除节点(度为 1 )](binary_search_tree.assets/bst_remove_case2.png) -

图 7-20   在二叉搜索树中删除节点(度为 1)

+

图 7-20   在二叉搜索树中删除节点(度为 1 )

当待删除节点的度为 $2$ 时,我们无法直接删除它,而需要使用一个节点替换该节点。由于要保持二叉搜索树“左 $<$ 根 $<$ 右”的性质,**因此这个节点可以是右子树的最小节点或左子树的最大节点**。 @@ -756,7 +756,7 @@ comments: true 2. 将 `tmp` 的值覆盖待删除节点的值,并在树中递归删除节点 `tmp` 。 === "<1>" - ![二叉搜索树删除节点示例](binary_search_tree.assets/bst_remove_case3_step1.png) + ![在二叉搜索树中删除节点(度为 2 )](binary_search_tree.assets/bst_remove_case3_step1.png) === "<2>" ![bst_remove_case3_step2](binary_search_tree.assets/bst_remove_case3_step2.png) @@ -767,7 +767,7 @@ comments: true === "<4>" ![bst_remove_case3_step4](binary_search_tree.assets/bst_remove_case3_step4.png) -

图 7-21   二叉搜索树删除节点示例

+

图 7-21   在二叉搜索树中删除节点(度为 2 )

删除节点操作同样使用 $O(\log n)$ 时间,其中查找待删除节点需要 $O(\log n)$ 时间,获取中序遍历后继节点需要 $O(\log n)$ 时间。