diff --git a/docs/chapter_data_structure/data_and_memory.md b/docs/chapter_data_structure/data_and_memory.md index 43cdbefe..e5aaba96 100644 --- a/docs/chapter_data_structure/data_and_memory.md +++ b/docs/chapter_data_structure/data_and_memory.md @@ -32,7 +32,7 @@ comments: true | 浮点数 | **float** | 4 bytes | $-3.4 \times 10^{38}$ ~ $3.4 \times 10^{38}$ | $0.0$ f | | | double | 8 bytes | $-1.7 \times 10^{308}$ ~ $1.7 \times 10^{308}$ | $0.0$ | | 字符 | **char** | 2 bytes / 1 byte | $0$ ~ $2^{16} - 1$ | $0$ | -| 布尔 | **boolean(bool)** | 1 byte / 1 bit | $\text{true}$ 或 $\text{false}$ | $\text{false}$ | +| 布尔 | **bool** | 1 byte / 1 bit | $\text{true}$ 或 $\text{false}$ | $\text{false}$ | diff --git a/docs/chapter_graph/graph_traversal.md b/docs/chapter_graph/graph_traversal.md index 3af3d720..e9d4012b 100644 --- a/docs/chapter_graph/graph_traversal.md +++ b/docs/chapter_graph/graph_traversal.md @@ -90,37 +90,37 @@ BFS 常借助「队列」来实现。队列具有“先入先出”的性质, 代码相对抽象,建议对照以下动画图示来加深理解。 -=== "Step 1" +=== "<1>"  -=== "Step 2" +=== "<2>"  -=== "Step 3" +=== "<3>"  -=== "Step 4" +=== "<4>"  -=== "Step 5" +=== "<5>"  -=== "Step 6" +=== "<6>"  -=== "Step 7" +=== "<7>"  -=== "Step 8" +=== "<8>"  -=== "Step 9" +=== "<9>"  -=== "Step 10" +=== "<10>"  -=== "Step 11" +=== "<11>"  !!! question "广度优先遍历的序列是否唯一?" @@ -212,37 +212,37 @@ BFS 常借助「队列」来实现。队列具有“先入先出”的性质, 为了加深理解,请你将图示与代码结合起来,在脑中(或者用笔画下来)模拟整个 DFS 过程,包括每个递归方法何时开启、何时返回。 -=== "Step 1" +=== "<1>"  -=== "Step 2" +=== "<2>"  -=== "Step 3" +=== "<3>"  -=== "Step 4" +=== "<4>"  -=== "Step 5" +=== "<5>"  -=== "Step 6" +=== "<6>"  -=== "Step 7" +=== "<7>"  -=== "Step 8" +=== "<8>"  -=== "Step 9" +=== "<9>"  -=== "Step 10" +=== "<10>"  -=== "Step 11" +=== "<11>"  !!! question "深度优先遍历的序列是否唯一?" diff --git a/docs/chapter_heap/heap.md b/docs/chapter_heap/heap.md index ed7dbaac..ea805e3a 100644 --- a/docs/chapter_heap/heap.md +++ b/docs/chapter_heap/heap.md @@ -454,22 +454,22 @@ comments: true 考虑从入堆结点开始,**从底至顶执行堆化**。具体地,比较插入结点与其父结点的值,若插入结点更大则将它们交换;并循环以上操作,从底至顶地修复堆中的各个结点;直至越过根结点时结束,或当遇到无需交换的结点时提前结束。 -=== "Step 1" +=== "<1>"  -=== "Step 2" +=== "<2>"  -=== "Step 3" +=== "<3>"  -=== "Step 4" +=== "<4>"  -=== "Step 5" +=== "<5>"  -=== "Step 6" +=== "<6>"  设结点总数为 $n$ ,则树的高度为 $O(\log n)$ ,易得堆化操作的循环轮数最多为 $O(\log n)$ ,**因而元素入堆操作的时间复杂度为 $O(\log n)$** 。 @@ -562,34 +562,34 @@ comments: true 顾名思义,**从顶至底堆化的操作方向与从底至顶堆化相反**,我们比较根结点的值与其两个子结点的值,将最大的子结点与根结点执行交换,并循环以上操作,直到越过叶结点时结束,或当遇到无需交换的结点时提前结束。 -=== "Step 1" +=== "<1>"  -=== "Step 2" +=== "<2>"  -=== "Step 3" +=== "<3>"  -=== "Step 4" +=== "<4>"  -=== "Step 5" +=== "<5>"  -=== "Step 6" +=== "<6>"  -=== "Step 7" +=== "<7>"  -=== "Step 8" +=== "<8>"  -=== "Step 9" +=== "<9>"  -=== "Step 10" +=== "<10>"  与元素入堆操作类似,**堆顶元素出堆操作的时间复杂度为 $O(\log n)$** 。 diff --git a/docs/chapter_introduction/algorithms_are_everywhere.md b/docs/chapter_introduction/algorithms_are_everywhere.md index 5d80f9c9..491dce97 100644 --- a/docs/chapter_introduction/algorithms_are_everywhere.md +++ b/docs/chapter_introduction/algorithms_are_everywhere.md @@ -18,15 +18,15 @@ comments: true 2. 由于在英文字母表中 $r$ 在 $m$ 的后面,因此应排除字典前半部分,查找范围仅剩后半部分; 3. 循环执行步骤 1-2 ,直到找到拼音首字母为 $r$ 的页码时终止。 -=== "Step 1" +=== "<1>"  -=== "Step 2" +=== "<2>"  -=== "Step 3" +=== "<3>"  -=== "Step 4" +=== "<4>"  -=== "Step 5" +=== "<5>"  查字典这个小学生的标配技能,实际上就是大名鼎鼎的「二分查找」。从数据结构角度,我们可以将字典看作是一个已排序的「数组」;而从算法角度,我们可将上述查字典的一系列指令看作是「二分查找」算法。 diff --git a/docs/chapter_searching/binary_search.md b/docs/chapter_searching/binary_search.md index 652ca629..1b489d74 100755 --- a/docs/chapter_searching/binary_search.md +++ b/docs/chapter_searching/binary_search.md @@ -28,25 +28,25 @@ $$ 首先,我们先采用“双闭区间”的表示,在数组 `nums` 中查找目标元素 `target` 的对应索引。 -=== "Step 1" +=== "<1>"  -=== "Step 2" +=== "<2>"  -=== "Step 3" +=== "<3>"  -=== "Step 4" +=== "<4>"  -=== "Step 5" +=== "<5>"  -=== "Step 6" +=== "<6>"  -=== "Step 7" +=== "<7>"  二分查找“双闭区间”表示下的代码如下所示。 diff --git a/docs/chapter_sorting/bubble_sort.md b/docs/chapter_sorting/bubble_sort.md index b2c396d2..79861d62 100755 --- a/docs/chapter_sorting/bubble_sort.md +++ b/docs/chapter_sorting/bubble_sort.md @@ -14,25 +14,25 @@ comments: true 完成此次冒泡操作后,**数组最大元素已在正确位置,接下来只需排序剩余 $n - 1$ 个元素**。 -=== "Step 1" +=== "<1>"  -=== "Step 2" +=== "<2>"  -=== "Step 3" +=== "<3>"  -=== "Step 4" +=== "<4>"  -=== "Step 5" +=== "<5>"  -=== "Step 6" +=== "<6>"  -=== "Step 7" +=== "<7>" 
Fig. 冒泡操作
diff --git a/docs/chapter_sorting/merge_sort.md b/docs/chapter_sorting/merge_sort.md index 82d2fd84..9933896f 100755 --- a/docs/chapter_sorting/merge_sort.md +++ b/docs/chapter_sorting/merge_sort.md @@ -24,34 +24,34 @@ comments: true 需要注意,由于从长度为 1 的子数组开始合并,所以 **每个子数组都是有序的**。因此,合并任务本质是要 **将两个有序子数组合并为一个有序数组**。 -=== "Step1" +=== "<1>"  -=== "Step2" +=== "<2>"  -=== "Step3" +=== "<3>"  -=== "Step4" +=== "<4>"  -=== "Step5" +=== "<5>"  -=== "Step6" +=== "<6>"  -=== "Step7" +=== "<7>"  -=== "Step8" +=== "<8>"  -=== "Step9" +=== "<9>"  -=== "Step10" +=== "<10>"  观察发现,归并排序的递归顺序就是二叉树的「后序遍历」。 diff --git a/docs/chapter_sorting/quick_sort.md b/docs/chapter_sorting/quick_sort.md index 42e8e441..9b1200a0 100755 --- a/docs/chapter_sorting/quick_sort.md +++ b/docs/chapter_sorting/quick_sort.md @@ -14,31 +14,31 @@ comments: true 「哨兵划分」执行完毕后,原数组被划分成两个部分,即 **左子数组** 和 **右子数组**,且满足 **左子数组任意元素 < 基准数 < 右子数组任意元素**。因此,接下来我们只需要排序两个子数组即可。 -=== "Step 1" +=== "<1>"  -=== "Step 2" +=== "<2>"  -=== "Step 3" +=== "<3>"  -=== "Step 4" +=== "<4>"  -=== "Step 5" +=== "<5>"  -=== "Step 6" +=== "<6>"  -=== "Step 7" +=== "<7>"  -=== "Step 8" +=== "<8>"  -=== "Step 9" +=== "<9>" Fig. 哨兵划分
diff --git a/docs/chapter_tree/avl_tree.md b/docs/chapter_tree/avl_tree.md index 41a35ba7..34b68176 100644 --- a/docs/chapter_tree/avl_tree.md +++ b/docs/chapter_tree/avl_tree.md @@ -313,16 +313,16 @@ AVL 树的独特之处在于「旋转 Rotation」的操作,其可 **在不影 如下图所示(结点下方为「平衡因子」),从底至顶看,二叉树中首个失衡结点是 **结点 3**。我们聚焦在以该失衡结点为根结点的子树上,将该结点记为 `node` ,将其左子结点记为 `child` ,执行「右旋」操作。完成右旋后,该子树已经恢复平衡,并且仍然为二叉搜索树。 -=== "Step 1" +=== "<1>"  -=== "Step 2" +=== "<2>"  -=== "Step 3" +=== "<3>"  -=== "Step 4" +=== "<4>"  进而,如果结点 `child` 本身有右子结点(记为 `grandChild` ),则需要在「右旋」中添加一步:将 `grandChild` 作为 `node` 的左子结点。 diff --git a/docs/chapter_tree/binary_search_tree.md b/docs/chapter_tree/binary_search_tree.md index e17daee0..dcfcbb35 100755 --- a/docs/chapter_tree/binary_search_tree.md +++ b/docs/chapter_tree/binary_search_tree.md @@ -21,16 +21,16 @@ comments: true - 若 `cur.val > num` ,说明目标结点在 `cur` 的左子树中,因此执行 `cur = cur.left` ; - 若 `cur.val = num` ,说明找到目标结点,跳出循环并返回该结点即可; -=== "Step 1" +=== "<1>"  -=== "Step 2" +=== "<2>"  -=== "Step 3" +=== "<3>"  -=== "Step 4" +=== "<4>"  二叉搜索树的查找操作和二分查找算法如出一辙,也是在每轮排除一半情况。循环次数最多为二叉树的高度,当二叉树平衡时,使用 $O(\log n)$ 时间。 @@ -188,16 +188,16 @@ comments: true 2. 在树中递归删除结点 `nex` ; 3. 使用 `nex` 替换待删除结点; -=== "Step 1" +=== "<1>"  -=== "Step 2" +=== "<2>"  -=== "Step 3" +=== "<3>"  -=== "Step 4" +=== "<4>"  删除结点操作也使用 $O(\log n)$ 时间,其中查找待删除结点 $O(\log n)$ ,获取中序遍历后继结点 $O(\log n)$ 。