From ff16c7eb750d0f30f0060b532b61c30bc87e60a4 Mon Sep 17 00:00:00 2001 From: krahets Date: Mon, 30 Oct 2023 05:12:30 +0800 Subject: [PATCH 1/7] Add the section of terminologies. --- docs/chapter_appendix/terminologies.md | 112 +++++++++++++++++++++++++ mkdocs.yml | 3 +- 2 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 docs/chapter_appendix/terminologies.md diff --git a/docs/chapter_appendix/terminologies.md b/docs/chapter_appendix/terminologies.md new file mode 100644 index 0000000000..fc283d778d --- /dev/null +++ b/docs/chapter_appendix/terminologies.md @@ -0,0 +1,112 @@ +# 术语表 + +下表列出了书中出现的重要术语。建议你同时记住它们的中英文叫法,以便阅读英文文献。 + +

表 数据结构与算法重要名词

+ +| 中文 | English | +| -------------- | ------------------------------ | +| 算法 | algorithm | +| 数据结构 | data structure | +| 渐近复杂度分析 | asymptotic complexity analysis | +| 时间复杂度 | time complexity | +| 空间复杂度 | space complexity | +| 迭代 | iteration | +| 递归 | recursion | +| 尾递归 | tail recursion | +| 递归树 | recursion tree | +| 大 $O$ 记号 | big-$O$ notation | +| 渐近上界 | asymptotic upper bound | +| 原码 | true form | +| 反码 | 1's complement code | +| 补码 | 2's complement code | +| 数组 | array | +| 索引 | index | +| 链表 | linked list | +| 链表节点 | list node | +| 列表 | list | +| 动态数组 | dynamic array | +| 栈 | stack | +| 队列 | queue | +| 双向队列 | double-ended queue | +| 哈希表 | hash table | +| 桶 | bucket | +| 哈希函数 | hash function | +| 哈希冲突 | hash collision | +| 负载因子 | load factor | +| 链式地址 | separate chaining | +| 开放寻址 | open addressing | +| 线性探测 | linear probing | +| 懒删除 | lazy deletion | +| 二叉树 | binary tree | +| 树节点 | tree node | +| 左子节点 | left-child node | +| 右子节点 | right-child node | +| 父节点 | parent node | +| 左子树 | left subtree | +| 右子树 | right subtree | +| 根节点 | root node | +| 叶节点 | leaf node | +| 边 | edge | +| 层 | level | +| 度 | degree | +| 高度 | height | +| 深度 | depth | +| 完美二叉树 | perfect binary tree | +| 完全二叉树 | complete binary tree | +| 完满二叉树 | full binary tree | +| 平衡二叉树 | balanced binary tree | +| 层序遍历 | level-order traversal | +| 广度优先遍历 | breadth-first traversal | +| 深度优先遍历 | depth-first traversal | +| 二叉搜索树 | binary search tree | +| 平衡二叉搜索树 | balanced binary search tree | +| 平衡因子 | balance factor | +| 堆 | heap | +| 大顶堆 | max heap | +| 小顶堆 | min heap | +| 优先队列 | priority queue | +| 堆化 | heapify | +| 图 | graph | +| 顶点 | vertex | +| 无向图 | undirected graph | +| 有向图 | directed graph | +| 连通图 | connected graph | +| 非连通图 | disconnected graph | +| 有权图 | weighted graph | +| 邻接 | adjacency | +| 路径 | path | +| 入度 | in-degree | +| 出度 | out-degree | +| 邻接矩阵 | adjacency matrix | +| 邻接表 | adjacency list | +| 广度优先搜索 | breadth-first search | +| 深度优先搜索 | depth-first search | +| 二分查找 | binary search | +| 搜索算法 | searching algorithm | +| 排序算法 | sorting algorithm | +| 选择排序 | selection sort | +| 冒泡排序 | bubble sort | +| 插入排序 | insertion sort | +| 快速排序 | quick sort | +| 归并排序 | merge sort | +| 堆排序 | heap sort | +| 桶排序 | bucket sort | +| 计数排序 | counting sort | +| 基数排序 | radix sort | +| 分治 | divide and conquer | +| 汉诺塔问题 | hanota problem | +| 回溯算法 | backtracking algorithm | +| 约束 | constraint | +| 解 | solution | +| 状态 | state | +| 剪枝 | pruning | +| 全排列问题 | Permutations problem | +| 子集和问题 | Subset-sum problem | +| N 皇后问题 | N-queens problem | +| 动态规划 | dynamic programming | +| 初始状态 | initial state | +| 状态转移方程 | state-trasition equation | +| 背包问题 | knapsack problem | +| 编辑距离问题 | edit distance problem | +| 贪心算法 | greedy algorithm | diff --git a/mkdocs.yml b/mkdocs.yml index a01c7ef6a7..da8bab546a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -167,7 +167,6 @@ nav: # [icon: material/timer-sand] - chapter_computational_complexity/index.md - 2.1   算法效率评估: chapter_computational_complexity/performance_evaluation.md - # [status: new] - 2.2   迭代与递归: chapter_computational_complexity/iteration_and_recursion.md - 2.3   时间复杂度: chapter_computational_complexity/time_complexity.md - 2.4   空间复杂度: chapter_computational_complexity/space_complexity.md @@ -286,5 +285,7 @@ nav: - chapter_appendix/index.md - 16.1   编程环境安装: chapter_appendix/installation.md - 16.2   一起参与创作: chapter_appendix/contribution.md + # [status: new] + - 16.3   术语表: chapter_appendix/terminologies.md - 参考文献: - chapter_reference/index.md From cb9d70dceb1c6d9208e22285c292efd8a46cddb2 Mon Sep 17 00:00:00 2001 From: krahets Date: Mon, 30 Oct 2023 05:13:42 +0800 Subject: [PATCH 2/7] fix format --- docs/chapter_appendix/terminologies.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/chapter_appendix/terminologies.md b/docs/chapter_appendix/terminologies.md index fc283d778d..23a1c4ae14 100644 --- a/docs/chapter_appendix/terminologies.md +++ b/docs/chapter_appendix/terminologies.md @@ -2,7 +2,7 @@ 下表列出了书中出现的重要术语。建议你同时记住它们的中英文叫法,以便阅读英文文献。 -

表 数据结构与算法重要名词

+

  数据结构与算法重要名词

| 中文 | English | | -------------- | ------------------------------ | From 04cf307ecf2d3fd7981fe397e5ceca46f999599b Mon Sep 17 00:00:00 2001 From: krahets Date: Thu, 14 Mar 2024 19:59:21 +0800 Subject: [PATCH 3/7] Fix median_three function for quick sort --- codes/c/chapter_sorting/quick_sort.c | 14 ++++++-------- codes/cpp/chapter_sorting/quick_sort.cpp | 14 ++++++-------- codes/csharp/chapter_sorting/quick_sort.cs | 14 ++++++-------- codes/dart/chapter_sorting/quick_sort.dart | 14 ++++++-------- codes/go/chapter_sorting/quick_sort.go | 12 ++++++------ codes/java/chapter_sorting/quick_sort.java | 14 ++++++-------- codes/javascript/chapter_sorting/quick_sort.js | 12 ++++++------ codes/python/chapter_sorting/quick_sort.py | 13 ++++++------- codes/rust/chapter_sorting/quick_sort.rs | 16 +++++++--------- codes/swift/chapter_sorting/quick_sort.swift | 15 +++++++++------ codes/typescript/chapter_sorting/quick_sort.ts | 17 ++++++----------- codes/zig/chapter_sorting/quick_sort.zig | 17 ++++++++--------- 12 files changed, 78 insertions(+), 94 deletions(-) diff --git a/codes/c/chapter_sorting/quick_sort.c b/codes/c/chapter_sorting/quick_sort.c index 1ecf6f7e81..34ac0f5d50 100644 --- a/codes/c/chapter_sorting/quick_sort.c +++ b/codes/c/chapter_sorting/quick_sort.c @@ -52,14 +52,12 @@ void quickSort(int nums[], int left, int right) { /* 快速排序类(中位基准数优化) */ // 选取三个元素的中位数 int medianThree(int nums[], int left, int mid, int right) { - // 此处使用异或运算来简化代码 - // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 - if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) - return left; - else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right])) - return mid; - else - return right; + int l = nums[left], m = nums[mid], r = nums[right]; + if ((l <= m && m <= r) || (r <= m && m <= l)) + return mid; // m 在 l 和 r 之间 + if ((m <= l && l <= r) || (r <= l && l <= m)) + return left; // l 在 m 和 r 之间 + return right; } // 哨兵划分(三数取中值) diff --git a/codes/cpp/chapter_sorting/quick_sort.cpp b/codes/cpp/chapter_sorting/quick_sort.cpp index 8b6ebb0380..28f1c26c46 100644 --- a/codes/cpp/chapter_sorting/quick_sort.cpp +++ b/codes/cpp/chapter_sorting/quick_sort.cpp @@ -57,14 +57,12 @@ class QuickSortMedian { /* 选取三个元素的中位数 */ static int medianThree(vector &nums, int left, int mid, int right) { - // 此处使用异或运算来简化代码 - // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 - if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) - return left; - else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right])) - return mid; - else - return right; + int l = nums[left], m = nums[mid], r = nums[right]; + if ((l <= m && m <= r) || (r <= m && m <= l)) + return mid; // m 在 l 和 r 之间 + if ((m <= l && l <= r) || (r <= l && l <= m)) + return left; // l 在 m 和 r 之间 + return right; } /* 哨兵划分(三数取中值) */ diff --git a/codes/csharp/chapter_sorting/quick_sort.cs b/codes/csharp/chapter_sorting/quick_sort.cs index a482758488..8d192e7f5c 100644 --- a/codes/csharp/chapter_sorting/quick_sort.cs +++ b/codes/csharp/chapter_sorting/quick_sort.cs @@ -49,14 +49,12 @@ static void Swap(int[] nums, int i, int j) { /* 选取三个元素的中位数 */ static int MedianThree(int[] nums, int left, int mid, int right) { - // 此处使用异或运算来简化代码 - // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 - if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) - return left; - else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right])) - return mid; - else - return right; + int l = nums[left], m = nums[mid], r = nums[right]; + if ((l <= m && m <= r) || (r <= m && m <= l)) + return mid; // m 在 l 和 r 之间 + if ((m <= l && l <= r) || (r <= l && l <= m)) + return left; // l 在 m 和 r 之间 + return right; } /* 哨兵划分(三数取中值) */ diff --git a/codes/dart/chapter_sorting/quick_sort.dart b/codes/dart/chapter_sorting/quick_sort.dart index 1b039c4815..6e1afb4fa6 100644 --- a/codes/dart/chapter_sorting/quick_sort.dart +++ b/codes/dart/chapter_sorting/quick_sort.dart @@ -49,14 +49,12 @@ class QuickSortMedian { /* 选取三个元素的中位数 */ static int _medianThree(List nums, int left, int mid, int right) { - // 此处使用异或运算来简化代码 - // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 - if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) - return left; - else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right])) - return mid; - else - return right; + int l = nums[left], m = nums[mid], r = nums[right]; + if ((l <= m && m <= r) || (r <= m && m <= l)) + return mid; // m 在 l 和 r 之间 + if ((m <= l && l <= r) || (r <= l && l <= m)) + return left; // l 在 m 和 r 之间 + return right; } /* 哨兵划分(三数取中值) */ diff --git a/codes/go/chapter_sorting/quick_sort.go b/codes/go/chapter_sorting/quick_sort.go index 5b74125841..ded0483d70 100644 --- a/codes/go/chapter_sorting/quick_sort.go +++ b/codes/go/chapter_sorting/quick_sort.go @@ -47,12 +47,12 @@ func (q *quickSort) quickSort(nums []int, left, right int) { /* 选取三个元素的中位数 */ func (q *quickSortMedian) medianThree(nums []int, left, mid, right int) int { - // 此处使用异或运算来简化代码(!= 在这里起到异或的作用) - // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 - if (nums[left] < nums[mid]) != (nums[left] < nums[right]) { - return left - } else if (nums[mid] < nums[left]) != (nums[mid] < nums[right]) { - return mid + l, m, r := nums[left], nums[mid], nums[right] + if (l <= m && m <= r) || (r <= m && m <= l) { + return mid // m 在 l 和 r 之间 + } + if (m <= l && l <= r) || (r <= l && l <= m) { + return left // l 在 m 和 r 之间 } return right } diff --git a/codes/java/chapter_sorting/quick_sort.java b/codes/java/chapter_sorting/quick_sort.java index 74d707ea2f..967c728852 100644 --- a/codes/java/chapter_sorting/quick_sort.java +++ b/codes/java/chapter_sorting/quick_sort.java @@ -56,14 +56,12 @@ static void swap(int[] nums, int i, int j) { /* 选取三个元素的中位数 */ static int medianThree(int[] nums, int left, int mid, int right) { - // 此处使用异或运算来简化代码 - // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 - if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) - return left; - else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right])) - return mid; - else - return right; + int l = nums[left], m = nums[mid], r = nums[right]; + if ((l <= m && m <= r) || (r <= m && m <= l)) + return mid; // m 在 l 和 r 之间 + if ((m <= l && l <= r) || (r <= l && l <= m)) + return left; // l 在 m 和 r 之间 + return right; } /* 哨兵划分(三数取中值) */ diff --git a/codes/javascript/chapter_sorting/quick_sort.js b/codes/javascript/chapter_sorting/quick_sort.js index 717f487b83..f1790025fd 100644 --- a/codes/javascript/chapter_sorting/quick_sort.js +++ b/codes/javascript/chapter_sorting/quick_sort.js @@ -55,12 +55,12 @@ class QuickSortMedian { /* 选取三个元素的中位数 */ medianThree(nums, left, mid, right) { - // 此处使用异或运算来简化代码 - // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 - if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) return left; - else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right])) - return mid; - else return right; + let l = nums[left], + m = nums[mid], + r = nums[right]; + if ((l <= m && m <= r) || (r <= m && m <= l)) return mid; // m 在 l 和 r 之间 + if ((m <= l && l <= r) || (r <= l && l <= m)) return left; // l 在 m 和 r 之间 + return right; } /* 哨兵划分(三数取中值) */ diff --git a/codes/python/chapter_sorting/quick_sort.py b/codes/python/chapter_sorting/quick_sort.py index 9257236291..a2c41d060b 100644 --- a/codes/python/chapter_sorting/quick_sort.py +++ b/codes/python/chapter_sorting/quick_sort.py @@ -39,13 +39,12 @@ class QuickSortMedian: """快速排序类(中位基准数优化)""" def median_three(self, nums: list[int], left: int, mid: int, right: int) -> int: - """选取三个元素的中位数""" - # 此处使用异或运算来简化代码 - # 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 - if (nums[left] < nums[mid]) ^ (nums[left] < nums[right]): - return left - elif (nums[mid] < nums[left]) ^ (nums[mid] < nums[right]): - return mid + """选取三个候选元素的中位数""" + l, m, r = nums[left], nums[mid], nums[right] + if (l <= m <= r) or (r <= m <= l): + return mid # m 在 l 和 r 之间 + if (m <= l <= r) or (r <= l <= m): + return left # l 在 m 和 r 之间 return right def partition(self, nums: list[int], left: int, right: int) -> int: diff --git a/codes/rust/chapter_sorting/quick_sort.rs b/codes/rust/chapter_sorting/quick_sort.rs index 314e0bac3f..b88986e807 100644 --- a/codes/rust/chapter_sorting/quick_sort.rs +++ b/codes/rust/chapter_sorting/quick_sort.rs @@ -46,13 +46,11 @@ struct QuickSortMedian; impl QuickSortMedian { /* 选取三个元素的中位数 */ fn median_three(nums: &mut [i32], left: usize, mid: usize, right: usize) -> usize { - // 此处使用异或运算来简化代码 - // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 - if (nums[left] < nums[mid]) ^ (nums[left] < nums[right]) { - return left; - } else if (nums[mid] < nums[left]) ^ (nums[mid] < nums[right]) { - return mid; - } + let l = nums[left], + m = nums[mid], + r = nums[right]; + if ((l <= m && m <= r) || (r <= m && m <= l)) return mid; // m 在 l 和 r 之间 + if ((m <= l && l <= r) || (r <= l && l <= m)) return left; // l 在 m 和 r 之间 right } @@ -73,8 +71,8 @@ impl QuickSortMedian { } nums.swap(i, j); // 交换这两个元素 } - nums.swap(i, left); // 将基准数交换至两子数组的分界线 - i // 返回基准数的索引 + nums.swap(i, left); // 将基准数交换至两子数组的分界线 + i // 返回基准数的索引 } /* 快速排序 */ diff --git a/codes/swift/chapter_sorting/quick_sort.swift b/codes/swift/chapter_sorting/quick_sort.swift index 8a94eef458..61c7294d9c 100644 --- a/codes/swift/chapter_sorting/quick_sort.swift +++ b/codes/swift/chapter_sorting/quick_sort.swift @@ -47,13 +47,16 @@ func quickSort(nums: inout [Int], left: Int, right: Int) { /* 快速排序类(中位基准数优化) */ /* 选取三个元素的中位数 */ func medianThree(nums: [Int], left: Int, mid: Int, right: Int) -> Int { - if (nums[left] < nums[mid]) != (nums[left] < nums[right]) { - return left - } else if (nums[mid] < nums[left]) != (nums[mid] < nums[right]) { - return mid - } else { - return right + let l = nums[left] + let m = nums[mid] + let r = nums[right] + if (l <= m && m <= r) || (r <= m && m <= l) { + return mid; // m 在 l 和 r 之间 } + if (m <= l && l <= r) || (r <= l && l <= m) { + return left; // l 在 m 和 r 之间 + } + return right; } /* 哨兵划分(三数取中值) */ diff --git a/codes/typescript/chapter_sorting/quick_sort.ts b/codes/typescript/chapter_sorting/quick_sort.ts index d19d5f7663..6865522ac5 100644 --- a/codes/typescript/chapter_sorting/quick_sort.ts +++ b/codes/typescript/chapter_sorting/quick_sort.ts @@ -62,17 +62,12 @@ class QuickSortMedian { mid: number, right: number ): number { - // 此处使用异或运算来简化代码 - // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 - if (Number(nums[left] < nums[mid]) ^ Number(nums[left] < nums[right])) { - return left; - } else if ( - Number(nums[mid] < nums[left]) ^ Number(nums[mid] < nums[right]) - ) { - return mid; - } else { - return right; - } + let l = nums[left], + m = nums[mid], + r = nums[right]; + if ((l <= m && m <= r) || (r <= m && m <= l)) return mid; // m 在 l 和 r 之间 + if ((m <= l && l <= r) || (r <= l && l <= m)) return left; // l 在 m 和 r 之间 + return right; } /* 哨兵划分(三数取中值) */ diff --git a/codes/zig/chapter_sorting/quick_sort.zig b/codes/zig/chapter_sorting/quick_sort.zig index cb89a1ddd4..b14f54eb5f 100644 --- a/codes/zig/chapter_sorting/quick_sort.zig +++ b/codes/zig/chapter_sorting/quick_sort.zig @@ -53,15 +53,14 @@ const QuickSortMedian = struct { // 选取三个元素的中位数 pub fn medianThree(nums: []i32, left: usize, mid: usize, right: usize) usize { - // 此处使用异或运算来简化代码 - // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 - if ((nums[left] < nums[mid]) != (nums[left] < nums[right])) { - return left; - } else if ((nums[mid] < nums[left]) != (nums[mid] < nums[right])) { - return mid; - } else { - return right; - } + var l = nums[left]; + var m = nums[mid]; + var r = nums[right]; + if ((l <= m && m <= r) || (r <= m && m <= l)) + return mid; // m 在 l 和 r 之间 + if ((m <= l && l <= r) || (r <= l && l <= m)) + return left; // l 在 m 和 r 之间 + return right; } // 哨兵划分(三数取中值) From 2e8959830938667cd3391d508ac590b8b26187e2 Mon Sep 17 00:00:00 2001 From: Yudong Jin Date: Thu, 14 Mar 2024 20:05:20 +0800 Subject: [PATCH 4/7] Delete docs/chapter_appendix/terminologies.md --- docs/chapter_appendix/terminologies.md | 112 ------------------------- 1 file changed, 112 deletions(-) delete mode 100644 docs/chapter_appendix/terminologies.md diff --git a/docs/chapter_appendix/terminologies.md b/docs/chapter_appendix/terminologies.md deleted file mode 100644 index 23a1c4ae14..0000000000 --- a/docs/chapter_appendix/terminologies.md +++ /dev/null @@ -1,112 +0,0 @@ -# 术语表 - -下表列出了书中出现的重要术语。建议你同时记住它们的中英文叫法,以便阅读英文文献。 - -

  数据结构与算法重要名词

- -| 中文 | English | -| -------------- | ------------------------------ | -| 算法 | algorithm | -| 数据结构 | data structure | -| 渐近复杂度分析 | asymptotic complexity analysis | -| 时间复杂度 | time complexity | -| 空间复杂度 | space complexity | -| 迭代 | iteration | -| 递归 | recursion | -| 尾递归 | tail recursion | -| 递归树 | recursion tree | -| 大 $O$ 记号 | big-$O$ notation | -| 渐近上界 | asymptotic upper bound | -| 原码 | true form | -| 反码 | 1's complement code | -| 补码 | 2's complement code | -| 数组 | array | -| 索引 | index | -| 链表 | linked list | -| 链表节点 | list node | -| 列表 | list | -| 动态数组 | dynamic array | -| 栈 | stack | -| 队列 | queue | -| 双向队列 | double-ended queue | -| 哈希表 | hash table | -| 桶 | bucket | -| 哈希函数 | hash function | -| 哈希冲突 | hash collision | -| 负载因子 | load factor | -| 链式地址 | separate chaining | -| 开放寻址 | open addressing | -| 线性探测 | linear probing | -| 懒删除 | lazy deletion | -| 二叉树 | binary tree | -| 树节点 | tree node | -| 左子节点 | left-child node | -| 右子节点 | right-child node | -| 父节点 | parent node | -| 左子树 | left subtree | -| 右子树 | right subtree | -| 根节点 | root node | -| 叶节点 | leaf node | -| 边 | edge | -| 层 | level | -| 度 | degree | -| 高度 | height | -| 深度 | depth | -| 完美二叉树 | perfect binary tree | -| 完全二叉树 | complete binary tree | -| 完满二叉树 | full binary tree | -| 平衡二叉树 | balanced binary tree | -| 层序遍历 | level-order traversal | -| 广度优先遍历 | breadth-first traversal | -| 深度优先遍历 | depth-first traversal | -| 二叉搜索树 | binary search tree | -| 平衡二叉搜索树 | balanced binary search tree | -| 平衡因子 | balance factor | -| 堆 | heap | -| 大顶堆 | max heap | -| 小顶堆 | min heap | -| 优先队列 | priority queue | -| 堆化 | heapify | -| 图 | graph | -| 顶点 | vertex | -| 无向图 | undirected graph | -| 有向图 | directed graph | -| 连通图 | connected graph | -| 非连通图 | disconnected graph | -| 有权图 | weighted graph | -| 邻接 | adjacency | -| 路径 | path | -| 入度 | in-degree | -| 出度 | out-degree | -| 邻接矩阵 | adjacency matrix | -| 邻接表 | adjacency list | -| 广度优先搜索 | breadth-first search | -| 深度优先搜索 | depth-first search | -| 二分查找 | binary search | -| 搜索算法 | searching algorithm | -| 排序算法 | sorting algorithm | -| 选择排序 | selection sort | -| 冒泡排序 | bubble sort | -| 插入排序 | insertion sort | -| 快速排序 | quick sort | -| 归并排序 | merge sort | -| 堆排序 | heap sort | -| 桶排序 | bucket sort | -| 计数排序 | counting sort | -| 基数排序 | radix sort | -| 分治 | divide and conquer | -| 汉诺塔问题 | hanota problem | -| 回溯算法 | backtracking algorithm | -| 约束 | constraint | -| 解 | solution | -| 状态 | state | -| 剪枝 | pruning | -| 全排列问题 | Permutations problem | -| 子集和问题 | Subset-sum problem | -| N 皇后问题 | N-queens problem | -| 动态规划 | dynamic programming | -| 初始状态 | initial state | -| 状态转移方程 | state-trasition equation | -| 背包问题 | knapsack problem | -| 编辑距离问题 | edit distance problem | -| 贪心算法 | greedy algorithm | From 30d7e636a8cdc4e8fa006b270917952a3e4fd594 Mon Sep 17 00:00:00 2001 From: Yudong Jin Date: Thu, 14 Mar 2024 20:08:09 +0800 Subject: [PATCH 5/7] Update quick_sort.ts --- codes/typescript/chapter_sorting/quick_sort.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/codes/typescript/chapter_sorting/quick_sort.ts b/codes/typescript/chapter_sorting/quick_sort.ts index 88dd08a367..f3ae3d8f31 100644 --- a/codes/typescript/chapter_sorting/quick_sort.ts +++ b/codes/typescript/chapter_sorting/quick_sort.ts @@ -65,8 +65,10 @@ class QuickSortMedian { let l = nums[left], m = nums[mid], r = nums[right]; - if ((l <= m && m <= r) || (r <= m && m <= l)) return mid; // m 在 l 和 r 之间 - if ((m <= l && l <= r) || (r <= l && l <= m)) return left; // l 在 m 和 r 之间 + // m 在 l 和 r 之间 + if ((l <= m && m <= r) || (r <= m && m <= l)) return mid; + // l 在 m 和 r 之间 + if ((m <= l && l <= r) || (r <= l && l <= m)) return left; return right; } From f3e319522dd2dd934f55b11564061a2da8e30a36 Mon Sep 17 00:00:00 2001 From: Yudong Jin Date: Thu, 14 Mar 2024 20:10:47 +0800 Subject: [PATCH 6/7] Update quick_sort.rs --- codes/rust/chapter_sorting/quick_sort.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/codes/rust/chapter_sorting/quick_sort.rs b/codes/rust/chapter_sorting/quick_sort.rs index 77dcf1c9a8..cd44248e20 100644 --- a/codes/rust/chapter_sorting/quick_sort.rs +++ b/codes/rust/chapter_sorting/quick_sort.rs @@ -46,11 +46,13 @@ struct QuickSortMedian; impl QuickSortMedian { /* 选取三个候选元素的中位数 */ fn median_three(nums: &mut [i32], left: usize, mid: usize, right: usize) -> usize { - let l = nums[left], - m = nums[mid], - r = nums[right]; - if ((l <= m && m <= r) || (r <= m && m <= l)) return mid; // m 在 l 和 r 之间 - if ((m <= l && l <= r) || (r <= l && l <= m)) return left; // l 在 m 和 r 之间 + let (mut l, mut m, mut r) = (nums[left], nums[mid], nums[right]); + if ((l <= m && m <= r) || (r <= m && m <= l)) { + return mid; // m 在 l 和 r 之间 + } + if ((m <= l && l <= r) || (r <= l && l <= m)) { + return left; // l 在 m 和 r 之间 + } right } From 52ed157b793694cad45566472b82deb85bff2062 Mon Sep 17 00:00:00 2001 From: Yudong Jin Date: Thu, 14 Mar 2024 20:11:56 +0800 Subject: [PATCH 7/7] Update quick_sort.js --- codes/javascript/chapter_sorting/quick_sort.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/codes/javascript/chapter_sorting/quick_sort.js b/codes/javascript/chapter_sorting/quick_sort.js index ab77c32443..fd96b2d167 100644 --- a/codes/javascript/chapter_sorting/quick_sort.js +++ b/codes/javascript/chapter_sorting/quick_sort.js @@ -58,8 +58,10 @@ class QuickSortMedian { let l = nums[left], m = nums[mid], r = nums[right]; - if ((l <= m && m <= r) || (r <= m && m <= l)) return mid; // m 在 l 和 r 之间 - if ((m <= l && l <= r) || (r <= l && l <= m)) return left; // l 在 m 和 r 之间 + // m 在 l 和 r 之间 + if ((l <= m && m <= r) || (r <= m && m <= l)) return mid; + // l 在 m 和 r 之间 + if ((m <= l && l <= r) || (r <= l && l <= m)) return left; return right; }