diff --git a/codes/dart/chapter_tree/binary_search_tree.dart b/codes/dart/chapter_tree/binary_search_tree.dart index 92beedb11..2443ba115 100644 --- a/codes/dart/chapter_tree/binary_search_tree.dart +++ b/codes/dart/chapter_tree/binary_search_tree.dart @@ -80,7 +80,7 @@ class BinarySearchTree { pre.left = node; } -/* 删除节点 */ + /* 删除节点 */ void remove(int num) { // 若树为空,直接提前返回 if (_root == null) return; diff --git a/docs/chapter_appendix/contribution.assets/edit_markdown.png b/docs/chapter_appendix/contribution.assets/edit_markdown.png index f2becc22d..30789481b 100644 Binary files a/docs/chapter_appendix/contribution.assets/edit_markdown.png and b/docs/chapter_appendix/contribution.assets/edit_markdown.png differ diff --git a/docs/chapter_computational_complexity/time_complexity.md b/docs/chapter_computational_complexity/time_complexity.md index 3eb11031d..7a752e33f 100755 --- a/docs/chapter_computational_complexity/time_complexity.md +++ b/docs/chapter_computational_complexity/time_complexity.md @@ -1587,7 +1587,7 @@ $$ 对数阶常出现于基于分治策略的算法中,体现了“一分为多”和“化繁为简”的算法思想。它增长缓慢,是仅次于常数阶的理想的时间复杂度。 -!!! tip +!!! tip "$O(\log n)$ 的底数是多少?" 准确来说,“一分为 $m$”对应的时间复杂度是 $O(\log_m n)$ 。而通过对数换底公式,我们可以得到具有不同底数的、相等的时间复杂度: diff --git a/docs/chapter_data_structure/number_encoding.md b/docs/chapter_data_structure/number_encoding.md index 18c145baa..d71c4aeee 100644 --- a/docs/chapter_data_structure/number_encoding.md +++ b/docs/chapter_data_structure/number_encoding.md @@ -23,8 +23,8 @@ $$ \begin{aligned} & 1 + (-2) \newline -& \rightarrow 0000 \space 0001 + 1000 \space 0010 \newline -& = 1000 \space 0011 \newline +& \rightarrow 0000 \; 0001 + 1000 \; 0010 \newline +& = 1000 \; 0011 \newline & \rightarrow -3 \end{aligned} $$ @@ -34,10 +34,10 @@ $$ $$ \begin{aligned} & 1 + (-2) \newline -& \rightarrow 0000 \space 0001 \space \text{(原码)} + 1000 \space 0010 \space \text{(原码)} \newline -& = 0000 \space 0001 \space \text{(反码)} + 1111 \space 1101 \space \text{(反码)} \newline -& = 1111 \space 1110 \space \text{(反码)} \newline -& = 1000 \space 0001 \space \text{(原码)} \newline +& \rightarrow 0000 \; 0001 \; \text{(原码)} + 1000 \; 0010 \; \text{(原码)} \newline +& = 0000 \; 0001 \; \text{(反码)} + 1111 \; 1101 \; \text{(反码)} \newline +& = 1111 \; 1110 \; \text{(反码)} \newline +& = 1000 \; 0001 \; \text{(原码)} \newline & \rightarrow -1 \end{aligned} $$ @@ -46,8 +46,8 @@ $$ $$ \begin{aligned} -+0 & \rightarrow 0000 \space 0000 \newline --0 & \rightarrow 1000 \space 0000 ++0 & \rightarrow 0000 \; 0000 \newline +-0 & \rightarrow 1000 \; 0000 \end{aligned} $$ @@ -55,25 +55,25 @@ $$ $$ \begin{aligned} --0 \rightarrow \space & 1000 \space 0000 \space \text{(原码)} \newline -= \space & 1111 \space 1111 \space \text{(反码)} \newline -= 1 \space & 0000 \space 0000 \space \text{(补码)} \newline +-0 \rightarrow \; & 1000 \; 0000 \; \text{(原码)} \newline += \; & 1111 \; 1111 \; \text{(反码)} \newline += 1 \; & 0000 \; 0000 \; \text{(补码)} \newline \end{aligned} $$ -在负零的反码基础上加 $1$ 会产生进位,但 `byte` 类型的长度只有 8 位,因此溢出到第 9 位的 $1$ 会被舍弃。也就是说,**负零的补码为 $0000 \space 0000$ ,与正零的补码相同**。这意味着在补码表示中只存在一个零,正负零歧义从而得到解决。 +在负零的反码基础上加 $1$ 会产生进位,但 `byte` 类型的长度只有 8 位,因此溢出到第 9 位的 $1$ 会被舍弃。也就是说,**负零的补码为 $0000 \; 0000$ ,与正零的补码相同**。这意味着在补码表示中只存在一个零,正负零歧义从而得到解决。 还剩余最后一个疑惑:`byte` 类型的取值范围是 $[-128, 127]$ ,多出来的一个负数 $-128$ 是如何得到的呢?我们注意到,区间 $[-127, +127]$ 内的所有整数都有对应的原码、反码和补码,并且原码和补码之间是可以互相转换的。 -然而,**补码 $1000 \space 0000$ 是一个例外,它并没有对应的原码**。根据转换方法,我们得到该补码的原码为 $0000 \space 0000$ 。这显然是矛盾的,因为该原码表示数字 $0$ ,它的补码应该是自身。计算机规定这个特殊的补码 $1000 \space 0000$ 代表 $-128$ 。实际上,$(-1) + (-127)$ 在补码下的计算结果就是 $-128$ 。 +然而,**补码 $1000 \; 0000$ 是一个例外,它并没有对应的原码**。根据转换方法,我们得到该补码的原码为 $0000 \; 0000$ 。这显然是矛盾的,因为该原码表示数字 $0$ ,它的补码应该是自身。计算机规定这个特殊的补码 $1000 \; 0000$ 代表 $-128$ 。实际上,$(-1) + (-127)$ 在补码下的计算结果就是 $-128$ 。 $$ \begin{aligned} & (-127) + (-1) \newline -& \rightarrow 1111 \space 1111 \space \text{(原码)} + 1000 \space 0001 \space \text{(原码)} \newline -& = 1000 \space 0000 \space \text{(反码)} + 1111 \space 1110 \space \text{(反码)} \newline -& = 1000 \space 0001 \space \text{(补码)} + 1111 \space 1111 \space \text{(补码)} \newline -& = 1000 \space 0000 \space \text{(补码)} \newline +& \rightarrow 1111 \; 1111 \; \text{(原码)} + 1000 \; 0001 \; \text{(原码)} \newline +& = 1000 \; 0000 \; \text{(反码)} + 1111 \; 1110 \; \text{(反码)} \newline +& = 1000 \; 0001 \; \text{(补码)} + 1111 \; 1111 \; \text{(补码)} \newline +& = 1000 \; 0000 \; \text{(补码)} \newline & \rightarrow -128 \end{aligned} $$ diff --git a/docs/chapter_searching/binary_search.md b/docs/chapter_searching/binary_search.md index 3891e1e2d..3715fe036 100755 --- a/docs/chapter_searching/binary_search.md +++ b/docs/chapter_searching/binary_search.md @@ -12,7 +12,7 @@ 接下来,循环执行以下两步。 -1. 计算中点索引 $m = \lfloor {(i + j) / 2} \rfloor$ ,其中 $\lfloor \space \rfloor$ 表示向下取整操作。 +1. 计算中点索引 $m = \lfloor {(i + j) / 2} \rfloor$ ,其中 $\lfloor \: \rfloor$ 表示向下取整操作。 2. 判断 `nums[m]` 和 `target` 的大小关系,分为以下三种情况。 1. 当 `nums[m] < target` 时,说明 `target` 在区间 $[m + 1, j]$ 中,因此执行 $i = m + 1$ 。 2. 当 `nums[m] > target` 时,说明 `target` 在区间 $[i, m - 1]$ 中,因此执行 $j = m - 1$ 。 diff --git a/docs/chapter_sorting/radix_sort.md b/docs/chapter_sorting/radix_sort.md index 2c8365328..f392c74aa 100644 --- a/docs/chapter_sorting/radix_sort.md +++ b/docs/chapter_sorting/radix_sort.md @@ -20,7 +20,7 @@ $$ x_k = \lfloor\frac{x}{d^{k-1}}\rfloor \bmod d $$ -其中 $\lfloor a \rfloor$ 表示对浮点数 $a$ 向下取整,而 $\bmod \space d$ 表示对 $d$ 取余。对于学号数据,$d = 10$ 且 $k \in [1, 8]$ 。 +其中 $\lfloor a \rfloor$ 表示对浮点数 $a$ 向下取整,而 $\bmod \: d$ 表示对 $d$ 取余。对于学号数据,$d = 10$ 且 $k \in [1, 8]$ 。 此外,我们需要小幅改动计数排序代码,使之可以根据数字的第 $k$ 位进行排序。