Several bug fixes and improvements (#945)

* Update Dockerfile for code debugging.

* Format Python code using Black.

* Improve dark theme by defining html classes for the figures, animations and cover images.

* Fix several glossary translation.

* Update a code comment.

* Fix climbing_stairs_backtrack: the pruning should not require the sorted choices list.

* Update the code of array and list traversal.

* Fix a rendering issue of README.md

* Update code of list traversal.

* Fix array_definition.png

* Update README.md

* Fix max_capacity_moving_short_board.png

* Fix array.dart

* Fix array.dart

* Fix array.dart

* Fix array.dart
This commit is contained in:
Yudong Jin
2023-11-14 21:27:35 +08:00
committed by GitHub
parent 9baf4a1753
commit fcbaf101a4
64 changed files with 212 additions and 218 deletions

View File

@ -2,6 +2,6 @@
<div class="center-table" markdown>
![附录](../assets/covers/chapter_appendix.jpg){ width="600" }
![附录](../assets/covers/chapter_appendix.jpg)
</div>

View File

@ -17,13 +17,13 @@
| 递归树 | recursion tree |
| 大 $O$ 记号 | big-$O$ notation |
| 渐近上界 | asymptotic upper bound |
| 原码 | true form |
| 反码 | 1's complement code |
| 补码 | 2's complement code |
| 原码 | signmagnitude |
| 反码 | 1's complement |
| 补码 | 2's complement |
| 数组 | array |
| 索引 | index |
| 链表 | linked list |
| 链表节点 | linked list node, list node |
| 链表节点 | linked list node, list node |
| 列表 | list |
| 动态数组 | dynamic array |
| 栈 | stack |
@ -56,8 +56,8 @@
| 完全二叉树 | complete binary tree |
| 完满二叉树 | full binary tree |
| 平衡二叉树 | balanced binary tree |
| AVL 树 | AVL tree |
| 红黑树 | red-black tree |
| AVL 树 | AVL tree |
| 红黑树 | red-black tree |
| 层序遍历 | level-order traversal |
| 广度优先遍历 | breadth-first traversal |
| 深度优先遍历 | depth-first traversal |

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -1,10 +1,6 @@
# 数组与链表
<div class="center-table" markdown>
![数组与链表](../assets/covers/chapter_array_and_linkedlist.jpg){ width="600" }
</div>
![数组与链表](../assets/covers/chapter_array_and_linkedlist.jpg)
!!! abstract

View File

@ -494,12 +494,11 @@
# 通过索引遍历列表
count = 0
for i in range(len(nums)):
count += 1
count += nums[i]
# 直接遍历列表元素
count = 0
for num in nums:
count += 1
count += num
```
=== "C++"
@ -508,13 +507,13 @@
/* 通过索引遍历列表 */
int count = 0;
for (int i = 0; i < nums.size(); i++) {
count++;
count += nums[i];
}
/* 直接遍历列表元素 */
count = 0;
for (int num : nums) {
count++;
count += num;
}
```
@ -524,13 +523,12 @@
/* 通过索引遍历列表 */
int count = 0;
for (int i = 0; i < nums.size(); i++) {
count++;
count += nums.get(i);
}
/* 直接遍历列表元素 */
count = 0;
for (int num : nums) {
count++;
count += num;
}
```
@ -540,13 +538,13 @@
/* 通过索引遍历列表 */
int count = 0;
for (int i = 0; i < nums.Count; i++) {
count++;
count += nums[i];
}
/* 直接遍历列表元素 */
count = 0;
foreach (int num in nums) {
count++;
count += num;
}
```
@ -556,13 +554,13 @@
/* 通过索引遍历列表 */
count := 0
for i := 0; i < len(nums); i++ {
count++
count += nums[i]
}
/* 直接遍历列表元素 */
count = 0
for range nums {
count++
for _, num := range nums {
count += num
}
```
@ -571,14 +569,14 @@
```swift title="list.swift"
/* 通过索引遍历列表 */
var count = 0
for _ in nums.indices {
count += 1
for i in nums.indices {
count += nums[i]
}
/* 直接遍历列表元素 */
count = 0
for _ in nums {
count += 1
for num in nums {
count += num
}
```
@ -588,13 +586,13 @@
/* 通过索引遍历列表 */
let count = 0;
for (let i = 0; i < nums.length; i++) {
count++;
count += nums[i];
}
/* 直接遍历列表元素 */
count = 0;
for (const num of nums) {
count++;
count += num;
}
```
@ -604,13 +602,13 @@
/* 通过索引遍历列表 */
let count = 0;
for (let i = 0; i < nums.length; i++) {
count++;
count += nums[i];
}
/* 直接遍历列表元素 */
count = 0;
for (const num of nums) {
count++;
count += num;
}
```
@ -619,30 +617,30 @@
```dart title="list.dart"
/* 通过索引遍历列表 */
int count = 0;
for (int i = 0; i < nums.length; i++) {
count++;
for (var i = 0; i < nums.length; i++) {
count += nums[i];
}
/* 直接遍历列表元素 */
count = 0;
for (int num in nums) {
count++;
for (var num in nums) {
count += num;
}
```
=== "Rust"
```rust title="list.rs"
/* 通过索引遍历列表 */
let mut count = 0;
for (index, value) in nums.iter().enumerate() {
count += 1;
// 通过索引遍历列表
let mut _count = 0;
for i in 0..nums.len() {
_count += nums[i];
}
/* 直接遍历列表元素 */
let mut count = 0;
for value in nums.iter() {
count += 1;
// 直接遍历列表元素
_count = 0;
for num in &nums {
_count += num;
}
```
@ -659,13 +657,13 @@
var count: i32 = 0;
var i: i32 = 0;
while (i < nums.items.len) : (i += 1) {
count += 1;
count += nums[i];
}
// 直接遍历列表元素
count = 0;
for (nums.items) |_| {
count += 1;
for (nums.items) |num| {
count += num;
}
```

View File

@ -33,7 +33,7 @@
不修改 `P.next` 也可以。从该链表的角度看,从头节点遍历到尾节点已经遇不到 `P` 了。这意味着节点 `P` 已经从链表中删除了,此时节点 `P` 指向哪里都不会对这条链表产生影响了。
从垃圾回收的角度看,对于 Java、Python、Go 等拥有自动垃圾回收的语言来说,节点 `P` 是否被回收取决于是否仍存在指向它的引用,而不是 `P.next` 的值。在 C 和 C++ 等语言中,我们需要手动释放节点内存。
从垃圾回收的角度看,对于 Java、Python、Go 等拥有自动垃圾回收的语言来说,节点 `P` 是否被回收取决于是否仍存在指向它的引用,而不是 `P.next` 的值。在 C 和 C++ 等语言中,我们需要手动释放节点内存。
!!! question "在链表中插入和删除操作的时间复杂度是 $O(1)$ 。但是增删之前都需要 $O(n)$ 查找元素,那为什么时间复杂度不是 $O(n)$ 呢?"

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![回溯](../assets/covers/chapter_backtracking.jpg){ width="600" }
![回溯](../assets/covers/chapter_backtracking.jpg)
</div>

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![复杂度分析](../assets/covers/chapter_complexity_analysis.jpg){ width="600" }
![复杂度分析](../assets/covers/chapter_complexity_analysis.jpg)
</div>

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![数据结构](../assets/covers/chapter_data_structure.jpg){ width="600" }
![数据结构](../assets/covers/chapter_data_structure.jpg)
</div>

View File

@ -18,7 +18,7 @@
![原码、反码与补码之间的相互转换](number_encoding.assets/1s_2s_complement.png)
「原码 true form」虽然最直观,但存在一些局限性。一方面,**负数的原码不能直接用于运算**。例如在原码下计算 $1 + (-2)$ ,得到的结果是 $-3$ ,这显然是不对的。
「原码 signmagnitude」虽然最直观,但存在一些局限性。一方面,**负数的原码不能直接用于运算**。例如在原码下计算 $1 + (-2)$ ,得到的结果是 $-3$ ,这显然是不对的。
$$
\begin{aligned}
@ -29,7 +29,7 @@ $$
\end{aligned}
$$
为了解决此问题,计算机引入了「反码 1's complement code」。如果我们先将原码转换为反码,并在反码下计算 $1 + (-2)$ ,最后将结果从反码转化回原码,则可得到正确结果 $-1$ 。
为了解决此问题,计算机引入了「反码 1's complement」。如果我们先将原码转换为反码并在反码下计算 $1 + (-2)$ ,最后将结果从反码转化回原码,则可得到正确结果 $-1$ 。
$$
\begin{aligned}
@ -51,7 +51,7 @@ $$
\end{aligned}
$$
与原码一样,反码也存在正负零歧义问题,因此计算机进一步引入了「补码 2's complement code」。我们先来观察一下负零的原码、反码、补码的转换过程:
与原码一样,反码也存在正负零歧义问题,因此计算机进一步引入了「补码 2's complement」。我们先来观察一下负零的原码、反码、补码的转换过程
$$
\begin{aligned}

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![分治](../assets/covers/chapter_divide_and_conquer.jpg){ width="600" }
![分治](../assets/covers/chapter_divide_and_conquer.jpg)
</div>

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![动态规划](../assets/covers/chapter_dynamic_programming.jpg){ width="600" }
![动态规划](../assets/covers/chapter_dynamic_programming.jpg)
</div>

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![](../assets/covers/chapter_graph.jpg){ width="600" }
![](../assets/covers/chapter_graph.jpg)
</div>

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![贪心](../assets/covers/chapter_greedy.jpg){ width="600" }
![贪心](../assets/covers/chapter_greedy.jpg)
</div>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![哈希表](../assets/covers/chapter_hashing.jpg){ width="600" }
![哈希表](../assets/covers/chapter_hashing.jpg)
</div>

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![](../assets/covers/chapter_heap.jpg){ width="600" }
![](../assets/covers/chapter_heap.jpg)
</div>

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![初识算法](../assets/covers/chapter_introduction.jpg){ width="600" }
![初识算法](../assets/covers/chapter_introduction.jpg)
</div>

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![前言](../assets/covers/chapter_preface.jpg){ width="600" }
![前言](../assets/covers/chapter_preface.jpg)
</div>

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![搜索](../assets/covers/chapter_searching.jpg){ width="600" }
![搜索](../assets/covers/chapter_searching.jpg)
</div>

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![排序](../assets/covers/chapter_sorting.jpg){ width="600" }
![排序](../assets/covers/chapter_sorting.jpg)
</div>

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![栈与队列](../assets/covers/chapter_stack_and_queue.jpg){ width="600" }
![栈与队列](../assets/covers/chapter_stack_and_queue.jpg)
</div>

View File

@ -2,7 +2,7 @@
<div class="center-table" markdown>
![](../assets/covers/chapter_tree.jpg){ width="600" }
![](../assets/covers/chapter_tree.jpg)
</div>

View File

@ -8,8 +8,8 @@ hide:
<h1 align="center"> </h1>
<p align="center">
<img src="index.assets/conceptual_rendering.png" width="250">
<img src="index.assets/hello_algo_mindmap_tp.png" width="400">
<img src="index.assets/conceptual_rendering.png" width="200">
<img src="index.assets/hello_algo_mindmap_tp.png" width="320">
</p>
<h2 align="center"> 《 Hello 算法 》</h2>