From 9f59c572b5a838617b1d1ed39d7cad438cb16bca Mon Sep 17 00:00:00 2001 From: krahets Date: Sun, 17 Sep 2023 01:13:15 +0800 Subject: [PATCH] fine tune --- .../c/chapter_computational_complexity/time_complexity.c | 2 +- .../worst_best_time_complexity.c | 2 +- codes/c/chapter_stack_and_queue/array_deque.c | 4 ++-- codes/c/chapter_stack_and_queue/array_queue.c | 2 +- codes/c/chapter_stack_and_queue/array_stack.c | 2 +- codes/c/chapter_stack_and_queue/linkedlist_deque.c | 4 ++-- codes/c/chapter_stack_and_queue/linkedlist_queue.c | 2 +- codes/c/chapter_tree/array_binary_tree.c | 8 ++++---- codes/cpp/utils/print_utils.hpp | 2 +- codes/dart/chapter_stack_and_queue/array_deque.dart | 4 ++-- codes/dart/chapter_stack_and_queue/array_queue.dart | 2 +- codes/dart/chapter_stack_and_queue/array_stack.dart | 2 +- codes/dart/chapter_stack_and_queue/deque.dart | 4 ++-- codes/dart/chapter_stack_and_queue/linkedlist_deque.dart | 6 +++--- codes/dart/chapter_stack_and_queue/linkedlist_queue.dart | 2 +- codes/dart/chapter_stack_and_queue/linkedlist_stack.dart | 2 +- codes/dart/chapter_stack_and_queue/queue.dart | 2 +- codes/dart/chapter_stack_and_queue/stack.dart | 2 +- codes/dart/chapter_tree/avl_tree.dart | 2 +- codes/dart/chapter_tree/binary_search_tree.dart | 2 +- codes/javascript/chapter_heap/top_k.js | 2 +- codes/python/chapter_graph/graph_adjacency_list.py | 2 +- codes/python/chapter_hashing/hash_map_chaining.py | 2 +- codes/python/modules/tree_node.py | 2 +- docs/chapter_appendix/installation.md | 8 ++++---- docs/chapter_array_and_linkedlist/list.md | 2 +- docs/chapter_backtracking/subset_sum_problem.md | 2 +- docs/chapter_computational_complexity/time_complexity.md | 2 +- docs/chapter_data_structure/number_encoding.md | 2 +- docs/chapter_dynamic_programming/dp_solution_pipeline.md | 2 +- docs/chapter_preface/about_the_book.md | 2 +- docs/chapter_tree/avl_tree.md | 2 +- 32 files changed, 44 insertions(+), 44 deletions(-) diff --git a/codes/c/chapter_computational_complexity/time_complexity.c b/codes/c/chapter_computational_complexity/time_complexity.c index 3f1986f0a..a7b3d5620 100644 --- a/codes/c/chapter_computational_complexity/time_complexity.c +++ b/codes/c/chapter_computational_complexity/time_complexity.c @@ -139,7 +139,7 @@ int main(int argc, char *argv[]) { count = linear(n); printf("线性阶的操作数量 = %d\n", count); - // 分配堆区内存(创建一维可变长数组:数组中元素数量为n,元素类型为int) + // 分配堆区内存(创建一维可变长数组:数组中元素数量为 n ,元素类型为 int ) int *nums = (int *)malloc(n * sizeof(int)); count = arrayTraversal(nums, n); printf("线性阶(遍历数组)的操作数量 = %d\n", count); diff --git a/codes/c/chapter_computational_complexity/worst_best_time_complexity.c b/codes/c/chapter_computational_complexity/worst_best_time_complexity.c index ef00a7a52..5ce3e8012 100644 --- a/codes/c/chapter_computational_complexity/worst_best_time_complexity.c +++ b/codes/c/chapter_computational_complexity/worst_best_time_complexity.c @@ -8,7 +8,7 @@ /* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */ int *randomNumbers(int n) { - // 分配堆区内存(创建一维可变长数组:数组中元素数量为n,元素类型为int) + // 分配堆区内存(创建一维可变长数组:数组中元素数量为 n ,元素类型为 int ) int *nums = (int *)malloc(n * sizeof(int)); // 生成数组 nums = { 1, 2, 3, ..., n } for (int i = 0; i < n; i++) { diff --git a/codes/c/chapter_stack_and_queue/array_deque.c b/codes/c/chapter_stack_and_queue/array_deque.c index dd6934df8..f197cca1c 100644 --- a/codes/c/chapter_stack_and_queue/array_deque.c +++ b/codes/c/chapter_stack_and_queue/array_deque.c @@ -150,10 +150,10 @@ int main() { /* 元素出队 */ int popLastNum = popLast(deque); - printf("队尾出队元素 = %d,队尾出队后 deque= ", popLastNum); + printf("队尾出队元素 = %d ,队尾出队后 deque= ", popLastNum); printArrayDeque(deque); int popFirstNum = popFirst(deque); - printf("队首出队元素 = %d,队首出队后 deque= ", popFirstNum); + printf("队首出队元素 = %d ,队首出队后 deque= ", popFirstNum); printArrayDeque(deque); /* 获取队列的长度 */ diff --git a/codes/c/chapter_stack_and_queue/array_queue.c b/codes/c/chapter_stack_and_queue/array_queue.c index da8fd27ab..f254d75d7 100644 --- a/codes/c/chapter_stack_and_queue/array_queue.c +++ b/codes/c/chapter_stack_and_queue/array_queue.c @@ -106,7 +106,7 @@ int main() { /* 元素出队 */ pop(queue); - printf("出队元素 pop = %d,出队后 queue = ", peekNum); + printf("出队元素 pop = %d ,出队后 queue = ", peekNum); printArrayQueue(queue); /* 获取队列的长度 */ diff --git a/codes/c/chapter_stack_and_queue/array_stack.c b/codes/c/chapter_stack_and_queue/array_stack.c index 4eec6e3fe..4baef306d 100644 --- a/codes/c/chapter_stack_and_queue/array_stack.c +++ b/codes/c/chapter_stack_and_queue/array_stack.c @@ -85,7 +85,7 @@ int main() { /* 元素出栈 */ val = pop(stack); - printf("出栈元素 pop = %d,出栈后 stack = ", val); + printf("出栈元素 pop = %d ,出栈后 stack = ", val); printArray(stack->data, stack->size); /* 获取栈的长度 */ diff --git a/codes/c/chapter_stack_and_queue/linkedlist_deque.c b/codes/c/chapter_stack_and_queue/linkedlist_deque.c index 186a1f4b0..8fcd7c1de 100644 --- a/codes/c/chapter_stack_and_queue/linkedlist_deque.c +++ b/codes/c/chapter_stack_and_queue/linkedlist_deque.c @@ -194,10 +194,10 @@ int main() { /* 元素出队 */ int popLastNum = popLast(deque); - printf("队尾出队元素 popLast = %d,队尾出队后 deque = ", popLastNum); + printf("队尾出队元素 popLast = %d ,队尾出队后 deque = ", popLastNum); printLinkedListDeque(deque); int popFirstNum = popFirst(deque); - printf("队首出队元素 popFirst = %d,队首出队后 deque = ", popFirstNum); + printf("队首出队元素 popFirst = %d ,队首出队后 deque = ", popFirstNum); printLinkedListDeque(deque); /* 获取队列的长度 */ diff --git a/codes/c/chapter_stack_and_queue/linkedlist_queue.c b/codes/c/chapter_stack_and_queue/linkedlist_queue.c index b579b8271..f24787dd7 100644 --- a/codes/c/chapter_stack_and_queue/linkedlist_queue.c +++ b/codes/c/chapter_stack_and_queue/linkedlist_queue.c @@ -110,7 +110,7 @@ int main() { /* 元素出队 */ pop(queue); - printf("出队元素 pop = %d,出队后 queue = ", peekNum); + printf("出队元素 pop = %d ,出队后 queue = ", peekNum); printLinkedListQueue(queue); /* 获取队列的长度 */ diff --git a/codes/c/chapter_tree/array_binary_tree.c b/codes/c/chapter_tree/array_binary_tree.c index 4f6b5c010..e02dc26ee 100644 --- a/codes/c/chapter_tree/array_binary_tree.c +++ b/codes/c/chapter_tree/array_binary_tree.c @@ -134,10 +134,10 @@ int main() { // 访问节点 int i = 1; int l = left(i), r = right(i), p = parent(i); - printf("\n当前节点的索引为 %d,值为 %d\n", i, val(abt, i)); - printf("其左子节点的索引为 %d,值为 %d\r\n", l, val(abt, l)); - printf("其右子节点的索引为 %d,值为 %d\r\n", r, val(abt, r)); - printf("其父节点的索引为 %d,值为 %d\r\n", p, val(abt, p)); + printf("\n当前节点的索引为 %d ,值为 %d\n", i, val(abt, i)); + printf("其左子节点的索引为 %d ,值为 %d\r\n", l, val(abt, l)); + printf("其右子节点的索引为 %d ,值为 %d\r\n", r, val(abt, r)); + printf("其父节点的索引为 %d ,值为 %d\r\n", p, val(abt, p)); // 遍历树 vector *res = levelOrder(abt); diff --git a/codes/cpp/utils/print_utils.hpp b/codes/cpp/utils/print_utils.hpp index 52342dde4..b0e71e719 100644 --- a/codes/cpp/utils/print_utils.hpp +++ b/codes/cpp/utils/print_utils.hpp @@ -200,7 +200,7 @@ template void printDeque(deque deque) { } /* Print a HashMap */ -// 定义模板参数 TKey 和 TValue,用于指定键值对的类型 +// 定义模板参数 TKey 和 TValue ,用于指定键值对的类型 template void printHashMap(unordered_map map) { for (auto kv : map) { cout << kv.first << " -> " << kv.second << '\n'; diff --git a/codes/dart/chapter_stack_and_queue/array_deque.dart b/codes/dart/chapter_stack_and_queue/array_deque.dart index c2c751fde..722867b00 100644 --- a/codes/dart/chapter_stack_and_queue/array_deque.dart +++ b/codes/dart/chapter_stack_and_queue/array_deque.dart @@ -132,9 +132,9 @@ void main() { /* 元素出队 */ final int popLast = deque.popLast(); - print("队尾出队元素 = $popLast,队尾出队后 deque = ${deque.toArray()}"); + print("队尾出队元素 = $popLast ,队尾出队后 deque = ${deque.toArray()}"); final int popFirst = deque.popFirst(); - print("队首出队元素 = $popFirst,队首出队后 deque = ${deque.toArray()}"); + print("队首出队元素 = $popFirst ,队首出队后 deque = ${deque.toArray()}"); /* 获取双向队列的长度 */ final int size = deque.size(); diff --git a/codes/dart/chapter_stack_and_queue/array_queue.dart b/codes/dart/chapter_stack_and_queue/array_queue.dart index d54bca1de..369af4c54 100644 --- a/codes/dart/chapter_stack_and_queue/array_queue.dart +++ b/codes/dart/chapter_stack_and_queue/array_queue.dart @@ -91,7 +91,7 @@ void main() { /* 元素出队 */ final int pop = queue.pop(); - print("出队元素 pop = $pop,出队后 queue = ${queue.toArray()}"); + print("出队元素 pop = $pop ,出队后 queue = ${queue.toArray()}"); /* 获取队列长度 */ final int size = queue.size(); diff --git a/codes/dart/chapter_stack_and_queue/array_stack.dart b/codes/dart/chapter_stack_and_queue/array_stack.dart index f8621c537..485d2359e 100644 --- a/codes/dart/chapter_stack_and_queue/array_stack.dart +++ b/codes/dart/chapter_stack_and_queue/array_stack.dart @@ -65,7 +65,7 @@ void main() { /* 元素出栈 */ final int pop = stack.pop(); - print("出栈元素 pop = $pop,出栈后 stack = ${stack.toArray()}"); + print("出栈元素 pop = $pop ,出栈后 stack = ${stack.toArray()}"); /* 获取栈的长度 */ final int size = stack.size(); diff --git a/codes/dart/chapter_stack_and_queue/deque.dart b/codes/dart/chapter_stack_and_queue/deque.dart index 2161f1041..9f9676d36 100644 --- a/codes/dart/chapter_stack_and_queue/deque.dart +++ b/codes/dart/chapter_stack_and_queue/deque.dart @@ -28,9 +28,9 @@ void main() { /* 元素出队 */ final int popLast = deque.removeLast(); - print("队尾出队元素 = $popLast,队尾出队后 deque = $deque"); + print("队尾出队元素 = $popLast ,队尾出队后 deque = $deque"); final int popFirst = deque.removeFirst(); - print("队首出队元素 = $popFirst,队首出队后 deque = $deque"); + print("队首出队元素 = $popFirst ,队首出队后 deque = $deque"); /* 获取双向队列的长度 */ final int size = deque.length; diff --git a/codes/dart/chapter_stack_and_queue/linkedlist_deque.dart b/codes/dart/chapter_stack_and_queue/linkedlist_deque.dart index d39cc703a..91df529c0 100644 --- a/codes/dart/chapter_stack_and_queue/linkedlist_deque.dart +++ b/codes/dart/chapter_stack_and_queue/linkedlist_deque.dart @@ -38,7 +38,7 @@ class LinkedListDeque { void push(int num, bool isFront) { final ListNode node = ListNode(num); if (isEmpty()) { - // 若链表为空,则令 _front,_rear 都指向 node + // 若链表为空,则令 _front 和 _rear 都指向 node _front = _rear = node; } else if (isFront) { // 队首入队操作 @@ -153,9 +153,9 @@ void main() { /* 元素出队 */ int? popLast = deque.popLast(); - print("队尾出队元素 = $popLast,队尾出队后 deque = ${deque.toArray()}"); + print("队尾出队元素 = $popLast ,队尾出队后 deque = ${deque.toArray()}"); int? popFirst = deque.popFirst(); - print("队首出队元素 = $popFirst,队首出队后 deque = ${deque.toArray()}"); + print("队首出队元素 = $popFirst ,队首出队后 deque = ${deque.toArray()}"); /* 获取双向队列的长度 */ int size = deque.size(); diff --git a/codes/dart/chapter_stack_and_queue/linkedlist_queue.dart b/codes/dart/chapter_stack_and_queue/linkedlist_queue.dart index 4ee392f62..cdd801ab7 100644 --- a/codes/dart/chapter_stack_and_queue/linkedlist_queue.dart +++ b/codes/dart/chapter_stack_and_queue/linkedlist_queue.dart @@ -91,7 +91,7 @@ void main() { /* 元素出队 */ final int pop = queue.pop(); - print("出队元素 pop = $pop,出队后 queue = ${queue.toArray()}"); + print("出队元素 pop = $pop ,出队后 queue = ${queue.toArray()}"); /* 获取队列的长度 */ final int size = queue.size(); diff --git a/codes/dart/chapter_stack_and_queue/linkedlist_stack.dart b/codes/dart/chapter_stack_and_queue/linkedlist_stack.dart index a1dbd46b7..44164db26 100644 --- a/codes/dart/chapter_stack_and_queue/linkedlist_stack.dart +++ b/codes/dart/chapter_stack_and_queue/linkedlist_stack.dart @@ -81,7 +81,7 @@ void main() { /* 元素出栈 */ final int pop = stack.pop(); - print("出栈元素 pop = $pop,出栈后 stack = ${stack.toList()}"); + print("出栈元素 pop = $pop ,出栈后 stack = ${stack.toList()}"); /* 获取栈的长度 */ final int size = stack.size(); diff --git a/codes/dart/chapter_stack_and_queue/queue.dart b/codes/dart/chapter_stack_and_queue/queue.dart index 2c01db5bd..0d6d24f24 100644 --- a/codes/dart/chapter_stack_and_queue/queue.dart +++ b/codes/dart/chapter_stack_and_queue/queue.dart @@ -25,7 +25,7 @@ void main() { /* 元素出队 */ final int pop = queue.removeFirst(); - print("出队元素 pop = $pop,出队后 queue = $queue"); + print("出队元素 pop = $pop ,出队后 queue = $queue"); /* 获取队列长度 */ final int size = queue.length; diff --git a/codes/dart/chapter_stack_and_queue/stack.dart b/codes/dart/chapter_stack_and_queue/stack.dart index 4fa9ee71b..e98230653 100644 --- a/codes/dart/chapter_stack_and_queue/stack.dart +++ b/codes/dart/chapter_stack_and_queue/stack.dart @@ -23,7 +23,7 @@ void main() { /* 元素出栈 */ final int pop = stack.removeLast(); - print("出栈元素 pop = $pop,出栈后 stack = $stack"); + print("出栈元素 pop = $pop ,出栈后 stack = $stack"); /* 获取栈的长度 */ final int size = stack.length; diff --git a/codes/dart/chapter_tree/avl_tree.dart b/codes/dart/chapter_tree/avl_tree.dart index 710d1c156..a8729638a 100644 --- a/codes/dart/chapter_tree/avl_tree.dart +++ b/codes/dart/chapter_tree/avl_tree.dart @@ -214,5 +214,5 @@ void main() { /* 查询节点 */ TreeNode? node = avlTree.search(7); - print("\n查找到的节点对象为 $node,节点值 = ${node!.val}"); + print("\n查找到的节点对象为 $node ,节点值 = ${node!.val}"); } diff --git a/codes/dart/chapter_tree/binary_search_tree.dart b/codes/dart/chapter_tree/binary_search_tree.dart index 3c60379aa..901466584 100644 --- a/codes/dart/chapter_tree/binary_search_tree.dart +++ b/codes/dart/chapter_tree/binary_search_tree.dart @@ -133,7 +133,7 @@ void main() { /* 查找节点 */ TreeNode? node = bst.search(7); - print("\n查找到的节点对象为 $node,节点值 = ${node?.val}"); + print("\n查找到的节点对象为 $node ,节点值 = ${node?.val}"); /* 插入节点 */ bst.insert(16); diff --git a/codes/javascript/chapter_heap/top_k.js b/codes/javascript/chapter_heap/top_k.js index a74461296..27c65af70 100644 --- a/codes/javascript/chapter_heap/top_k.js +++ b/codes/javascript/chapter_heap/top_k.js @@ -8,7 +8,7 @@ const { MaxHeap } = require('./my_heap'); /* 基于堆查找数组中最大的 k 个元素 */ function topKHeap(nums, k) { - // 使用大顶堆 MaxHeap,对数组 nums 取相反数 + // 使用大顶堆 MaxHeap ,对数组 nums 取相反数 const invertedNums = nums.map((num) => -num); // 将数组的前 k 个元素入堆 const heap = new MaxHeap(invertedNums.slice(0, k)); diff --git a/codes/python/chapter_graph/graph_adjacency_list.py b/codes/python/chapter_graph/graph_adjacency_list.py index a82191a8d..db8e534bc 100644 --- a/codes/python/chapter_graph/graph_adjacency_list.py +++ b/codes/python/chapter_graph/graph_adjacency_list.py @@ -16,7 +16,7 @@ class GraphAdjList: def __init__(self, edges: list[list[Vertex]]): """构造方法""" # 邻接表,key: 顶点,value:该顶点的所有邻接顶点 - self.adj_list = dict[Vertex, Vertex]() + self.adj_list = dict[Vertex, list[Vertex]]() # 添加所有顶点和边 for edge in edges: self.add_vertex(edge[0]) diff --git a/codes/python/chapter_hashing/hash_map_chaining.py b/codes/python/chapter_hashing/hash_map_chaining.py index fdbaa28b6..96769eb5e 100644 --- a/codes/python/chapter_hashing/hash_map_chaining.py +++ b/codes/python/chapter_hashing/hash_map_chaining.py @@ -92,7 +92,7 @@ class HashMapChaining: """Driver Code""" if __name__ == "__main__": - # 测试代码 + # 初始化哈希表 hashmap = HashMapChaining() # 添加操作 diff --git a/codes/python/modules/tree_node.py b/codes/python/modules/tree_node.py index ead12eede..4aebcd9e9 100644 --- a/codes/python/modules/tree_node.py +++ b/codes/python/modules/tree_node.py @@ -35,7 +35,7 @@ class TreeNode: def list_to_tree_dfs(arr: list[int], i: int) -> TreeNode | None: """将列表反序列化为二叉树:递归""" - # 如果索引超出数组长度,或者对应的元素为 None,返回 None + # 如果索引超出数组长度,或者对应的元素为 None ,则返回 None if i < 0 or i >= len(arr) or arr[i] is None: return None # 构建当前节点 diff --git a/docs/chapter_appendix/installation.md b/docs/chapter_appendix/installation.md index 414c3d9f2..5f2ab5e73 100644 --- a/docs/chapter_appendix/installation.md +++ b/docs/chapter_appendix/installation.md @@ -41,8 +41,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)。 +1. 下载并安装 [Swift](https://www.swift.org/download/) 。 +2. 在 VSCode 的插件市场中搜索 `swift` ,安装 [Swift for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang) 。 ### Dart 环境 @@ -51,5 +51,5 @@ ### 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)。 +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/docs/chapter_array_and_linkedlist/list.md b/docs/chapter_array_and_linkedlist/list.md index 965cfabcd..68c24d75f 100755 --- a/docs/chapter_array_and_linkedlist/list.md +++ b/docs/chapter_array_and_linkedlist/list.md @@ -857,7 +857,7 @@ 为了加深对列表工作原理的理解,我们尝试实现一个简易版列表,包括以下三个重点设计。 - **初始容量**:选取一个合理的数组初始容量。在本示例中,我们选择 10 作为初始容量。 -- **数量记录**:声明一个变量 size,用于记录列表当前元素数量,并随着元素插入和删除实时更新。根据此变量,我们可以定位列表尾部,以及判断是否需要扩容。 +- **数量记录**:声明一个变量 `size` ,用于记录列表当前元素数量,并随着元素插入和删除实时更新。根据此变量,我们可以定位列表尾部,以及判断是否需要扩容。 - **扩容机制**:若插入元素时列表容量已满,则需要进行扩容。首先根据扩容倍数创建一个更大的数组,再将当前数组的所有元素依次移动至新数组。在本示例中,我们规定每次将数组扩容至之前的 2 倍。 === "Python" diff --git a/docs/chapter_backtracking/subset_sum_problem.md b/docs/chapter_backtracking/subset_sum_problem.md index 31684da17..111cecc65 100644 --- a/docs/chapter_backtracking/subset_sum_problem.md +++ b/docs/chapter_backtracking/subset_sum_problem.md @@ -148,7 +148,7 @@ 除此之外,我们还对代码进行了以下两项优化。 - 在开启搜索前,先将数组 `nums` 排序。在遍历所有选择时,**当子集和超过 `target` 时直接结束循环**,因为后边的元素更大,其子集和都一定会超过 `target` 。 -- 省去元素和变量 `total`,**通过在 `target` 上执行减法来统计元素和**,当 `target` 等于 $0$ 时记录解。 +- 省去元素和变量 `total` ,**通过在 `target` 上执行减法来统计元素和**,当 `target` 等于 $0$ 时记录解。 === "Python" diff --git a/docs/chapter_computational_complexity/time_complexity.md b/docs/chapter_computational_complexity/time_complexity.md index 4af1fd616..6bf2c121f 100755 --- a/docs/chapter_computational_complexity/time_complexity.md +++ b/docs/chapter_computational_complexity/time_complexity.md @@ -3,7 +3,7 @@ 运行时间可以直观且准确地反映算法的效率。如果我们想要准确预估一段代码的运行时间,应该如何操作呢? 1. **确定运行平台**,包括硬件配置、编程语言、系统环境等,这些因素都会影响代码的运行效率。 -2. **评估各种计算操作所需的运行时间**,例如加法操作 `+` 需要 1 ns,乘法操作 `*` 需要 10 ns,打印操作 `print()` 需要 5 ns 等。 +2. **评估各种计算操作所需的运行时间**,例如加法操作 `+` 需要 1 ns ,乘法操作 `*` 需要 10 ns ,打印操作 `print()` 需要 5 ns 等。 3. **统计代码中所有的计算操作**,并将所有操作的执行时间求和,从而得到运行时间。 例如在以下代码中,输入数据大小为 $n$ : diff --git a/docs/chapter_data_structure/number_encoding.md b/docs/chapter_data_structure/number_encoding.md index d71c4aeee..839e13745 100644 --- a/docs/chapter_data_structure/number_encoding.md +++ b/docs/chapter_data_structure/number_encoding.md @@ -88,7 +88,7 @@ $$ ## 浮点数编码 -细心的你可能会发现:`int` 和 `float` 长度相同,都是 4 bytes,但为什么 `float` 的取值范围远大于 `int` ?这非常反直觉,因为按理说 `float` 需要表示小数,取值范围应该变小才对。 +细心的你可能会发现:`int` 和 `float` 长度相同,都是 4 bytes ,但为什么 `float` 的取值范围远大于 `int` ?这非常反直觉,因为按理说 `float` 需要表示小数,取值范围应该变小才对。 实际上,**这是因为浮点数 `float` 采用了不同的表示方式**。记一个 32-bit 长度的二进制数为: diff --git a/docs/chapter_dynamic_programming/dp_solution_pipeline.md b/docs/chapter_dynamic_programming/dp_solution_pipeline.md index a5762b139..26826972b 100644 --- a/docs/chapter_dynamic_programming/dp_solution_pipeline.md +++ b/docs/chapter_dynamic_programming/dp_solution_pipeline.md @@ -75,7 +75,7 @@ $$ **第三步:确定边界条件和状态转移顺序** -在本题中,处在首行的状态只能向右转移,首列状态只能向下转移,因此首行 $i = 0$ 和首列 $j = 0$ 是边界条件。 +在本题中,首行的状态只能从其左边的状态得来,首列的状态只能从其上边的状态得来,因此首行 $i = 0$ 和首列 $j = 0$ 是边界条件。 如下图所示,由于每个格子是由其左方格子和上方格子转移而来,因此我们使用采用循环来遍历矩阵,外循环遍历各行、内循环遍历各列。 diff --git a/docs/chapter_preface/about_the_book.md b/docs/chapter_preface/about_the_book.md index 4458999f3..147cd0818 100644 --- a/docs/chapter_preface/about_the_book.md +++ b/docs/chapter_preface/about_the_book.md @@ -35,7 +35,7 @@ - 感谢我在公司的导师李汐博士,在一次畅谈中您鼓励我“快行动起来”,坚定了我写这本书的决心。 - 感谢我的女朋友泡泡作为本书的首位读者,从算法小白的角度提出许多宝贵建议,使得本书更适合新手阅读。 - 感谢腾宝、琦宝、飞宝为本书起了一个富有创意的名字,唤起大家写下第一行代码 "Hello World!" 的美好回忆。 -- 感谢苏潼为本书设计了精美的封面和 LOGO,并在我的强迫症下多次耐心修改。 +- 感谢苏潼为本书设计了精美的封面和 LOGO ,并在我的强迫症下多次耐心修改。 - 感谢 @squidfunk 提供的写作排版建议,以及他开发的开源文档主题 [Material-for-MkDocs](https://github.com/squidfunk/mkdocs-material/tree/master) 。 在写作过程中,我阅读了许多关于数据结构与算法的教材和文章。这些作品为本书提供了优秀的范本,确保了本书内容的准确性与品质。在此感谢所有老师和前辈们的杰出贡献! diff --git a/docs/chapter_tree/avl_tree.md b/docs/chapter_tree/avl_tree.md index 903658b88..2b0271c85 100644 --- a/docs/chapter_tree/avl_tree.md +++ b/docs/chapter_tree/avl_tree.md @@ -1,6 +1,6 @@ # AVL 树 * -在二叉搜索树章节中,我们提到了在多次插入和删除操作后,二叉搜索树可能退化为链表。这种情况下,所有操作的时间复杂度将从 $O(\log n)$ 恶化为 $O(n)$。 +在二叉搜索树章节中,我们提到了在多次插入和删除操作后,二叉搜索树可能退化为链表。这种情况下,所有操作的时间复杂度将从 $O(\log n)$ 恶化为 $O(n)$ 。 如下图所示,经过两次删除节点操作,这个二叉搜索树便会退化为链表。