Skip to content

Commit abf1f11

Browse files
authored
Bug fixes and improvements (#1581)
* A bug fixes * Sync zh and zh-hant versions. * Fix a question in chapter_array_and_linkedlist/summary.md * Optimize a definition in what_is_dsa.md * Fix the Contributing guidelines for Chinese-to-English. * Add a q&a in chapter_array_and_linkedlist/summary.md * Sync zh and zh-hant versions. * Update .gitignore * Sync zh and zh-hant versions.
1 parent 6348dbe commit abf1f11

File tree

11 files changed

+38
-21
lines changed

11 files changed

+38
-21
lines changed

Diff for: .gitignore

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# macOS
22
.DS_Store
33

4-
# Editor
4+
# editors
55
.vscode/
66
**/.idea
77

@@ -12,6 +12,3 @@
1212
/build
1313
/site
1414
/utils
15-
16-
# test script
17-
test.sh

Diff for: docs/chapter_array_and_linkedlist/summary.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@
7171

7272
另一方面,必要使用链表的情况主要是二叉树和图。栈和队列往往会使用编程语言提供的 `stack``queue` ,而非链表。
7373

74-
**Q**初始化列表 `res = [0] * self.size()` 操作,会导致 `res` 的每个元素引用相同的地址吗
74+
**Q**操作 `res = [[0]] * n` 生成了一个二维列表,其中每一个 `[0]` 都是独立的吗
7575

76-
不会。但二维数组会有这个问题,例如初始化二维列表 `res = [[0]] * self.size()` ,则多次引用了同一个列表 `[0]`
76+
不是独立的。此二维列表中,所有的 `[0]` 实际上是同一个对象的引用。如果我们修改其中一个元素,会发现所有的对应元素都会随之改变。
77+
78+
如果希望二维列表中的每个 `[0]` 都是独立的,可以使用 `res = [[0] for _ in range(n)]` 来实现。这种方式的原理是初始化了 $n$ 个独立的 `[0]` 列表对象。
79+
80+
**Q**:操作 `res = [0] * n` 生成了一个列表,其中每一个整数 0 都是独立的吗?
81+
82+
在该列表中,所有整数 0 都是同一个对象的引用。这是因为 Python 对小整数(通常是 -5 到 256)采用了缓存池机制,以便最大化对象复用,从而提升性能。
83+
84+
虽然它们指向同一个对象,但我们仍然可以独立修改列表中的每个元素,这是因为 Python 的整数是“不可变对象”。当我们修改某个元素时,实际上是切换为另一个对象的引用,而不是改变原有对象本身。
85+
86+
然而,当列表元素是“可变对象”时(例如列表、字典或类实例等),修改某个元素会直接改变该对象本身,所有引用该对象的元素都会产生相同变化。

Diff for: docs/chapter_introduction/summary.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- 整理扑克的过程与插入排序算法非常类似。插入排序算法适合排序小型数据集。
66
- 货币找零的步骤本质上是贪心算法,每一步都采取当前看来最好的选择。
77
- 算法是在有限时间内解决特定问题的一组指令或操作步骤,而数据结构是计算机中组织和存储数据的方式。
8-
- 数据结构与算法紧密相连。数据结构是算法的基石,而算法是数据结构发挥作用的舞台
8+
- 数据结构与算法紧密相连。数据结构是算法的基石,而算法为数据结构注入生命力
99
- 我们可以将数据结构与算法类比为拼装积木,积木代表数据,积木的形状和连接方式等代表数据结构,拼装积木的步骤则对应算法。
1010

1111
### Q & A

Diff for: docs/chapter_introduction/what_is_dsa.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
如下图所示,数据结构与算法高度相关、紧密结合,具体表现在以下三个方面。
2727

2828
- 数据结构是算法的基石。数据结构为算法提供了结构化存储的数据,以及操作数据的方法。
29-
- 算法是数据结构发挥作用的舞台。数据结构本身仅存储数据信息,结合算法才能解决特定问题。
29+
- 算法为数据结构注入生命力。数据结构本身仅存储数据信息,结合算法才能解决特定问题。
3030
- 算法通常可以基于不同的数据结构实现,但执行效率可能相差很大,选择合适的数据结构是关键。
3131

3232
![数据结构与算法的关系](what_is_dsa.assets/relationship_between_data_structure_and_algorithm.png)

Diff for: en/CONTRIBUTING.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ That is, our contributors are computer scientists, engineers, and students from
3232
> [!important]
3333
> Before diving in, ensure you're comfortable with the GitHub pull request workflow and have read the "Translation standards" and "Pseudo-code for translation" below.
3434
35-
1. **Self-assignment**: Visit [GitHub projects](https://github.com/users/krahets/projects/2/views/4) to select an unclaimed task and mark it as `In Progress`.
36-
2. **Translation**: We encourage preserving the original meaning while ensuring the translation is natural and fluent.
37-
3. **Peer review**: Please carefully check your changes before submitting a Pull Request (PR). After approval by two reviewers, it will be merged into the project.
35+
1. **Task assignment**: Self-assign a task in the Notion workspace.
36+
2. **Translation**: Optimize the translation on your local PC, referring to the “Translation Pseudo-Code” section below for more details.
37+
3. **Peer review**: Carefully review your changes before submitting a Pull Request (PR). The PR will be merged into the main branch after approval from two reviewers.
3838

3939
## Translation standards
4040

4141
> [!tip]
42-
> The "Accuracy" and "Authenticity" are primarily handled by native Chinese speakers and native English speakers, respectively.
42+
> **The "Accuracy" and "Authenticity" are primarily handled by native Chinese speakers and native English speakers, respectively.**
4343
>
4444
> In some instances, "Accuracy (consistency)" and "Authenticity" represent a trade-off, where optimizing one aspect could significantly affect the other. In such cases, please leave a comment in the pull request for discussion.
4545

Diff for: en/docs/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ <h3>English version reviewers</h3>
414414
<!-- contributors -->
415415
<div style="margin: 2em auto;">
416416
<h3>Contributors</h3>
417-
<p>This book has been optimized by the efforts of over 180 contributors. We sincerely thank them for their invaluable time and contributions!</p>
417+
<p>This book has been refined by the efforts of over 180 contributors. We sincerely thank them for their invaluable time and contributions!</p>
418418
<a href="https://github.com/krahets/hello-algo/graphs/contributors">
419419
<img src="https://contrib.rocks/image?repo=krahets/hello-algo&max=300&columns=16" alt="Contributors" style="width: 100%; max-width: 38.5em;">
420420
</a>

Diff for: zh-hant/codes/cpp/chapter_tree/array_binary_tree.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ int main() {
115115
int i = 1;
116116
int l = abt.left(i), r = abt.right(i), p = abt.parent(i);
117117
cout << "\n當前節點的索引為 " << i << ",值為 " << abt.val(i) << "\n";
118-
cout << "其左子節點的索引為 " << l << ",值為 " << (l != INT_MAX ? to_string(abt.val(l)) : "nullptr") << "\n";
119-
cout << "其右子節點的索引為 " << r << ",值為 " << (r != INT_MAX ? to_string(abt.val(r)) : "nullptr") << "\n";
120-
cout << "其父節點的索引為 " << p << ",值為 " << (p != INT_MAX ? to_string(abt.val(p)) : "nullptr") << "\n";
118+
cout << "其左子節點的索引為 " << l << ",值為 " << (abt.val(l) != INT_MAX ? to_string(abt.val(l)) : "nullptr") << "\n";
119+
cout << "其右子節點的索引為 " << r << ",值為 " << (abt.val(r) != INT_MAX ? to_string(abt.val(r)) : "nullptr") << "\n";
120+
cout << "其父節點的索引為 " << p << ",值為 " << (abt.val(p) != INT_MAX ? to_string(abt.val(p)) : "nullptr") << "\n";
121121

122122
// 走訪樹
123123
vector<int> res = abt.levelOrder();

Diff for: zh-hant/docs/chapter_array_and_linkedlist/summary.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@
7171

7272
另一方面,必要使用鏈結串列的情況主要是二元樹和圖。堆疊和佇列往往會使用程式語言提供的 `stack``queue` ,而非鏈結串列。
7373

74-
**Q**初始化串列 `res = [0] * self.size()` 操作,會導致 `res` 的每個元素引用相同的位址嗎
74+
**Q**操作 `res = [[0]] * n` 生成了一個二維串列,其中每一個 `[0]` 都是獨立的嗎
7575

76-
不會。但二維陣列會有這個問題,例如初始化二維串列 `res = [[0]] * self.size()` ,則多次引用了同一個串列 `[0]`
76+
不是獨立的。此二維串列中,所有的 `[0]` 實際上是同一個物件的引用。如果我們修改其中一個元素,會發現所有的對應元素都會隨之改變。
77+
78+
如果希望二維串列中的每個 `[0]` 都是獨立的,可以使用 `res = [[0] for _ in range(n)]` 來實現。這種方式的原理是初始化了 $n$ 個獨立的 `[0]` 串列物件。
79+
80+
**Q**:操作 `res = [0] * n` 生成了一個串列,其中每一個整數 0 都是獨立的嗎?
81+
82+
在該串列中,所有整數 0 都是同一個物件的引用。這是因為 Python 對小整數(通常是 -5 到 256)採用了快取池機制,以便最大化物件複用,從而提升效能。
83+
84+
雖然它們指向同一個物件,但我們仍然可以獨立修改串列中的每個元素,這是因為 Python 的整數是“不可變物件”。當我們修改某個元素時,實際上是切換為另一個物件的引用,而不是改變原有物件本身。
85+
86+
然而,當串列元素是“可變物件”時(例如串列、字典或類別例項等),修改某個元素會直接改變該物件本身,所有引用該物件的元素都會產生相同變化。

Diff for: zh-hant/docs/chapter_computational_complexity/time_complexity.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ $$
11201120

11211121
生物學的“細胞分裂”是指數階增長的典型例子:初始狀態為 $1$ 個細胞,分裂一輪後變為 $2$ 個,分裂兩輪後變為 $4$ 個,以此類推,分裂 $n$ 輪後有 $2^n$ 個細胞。
11221122

1123-
下圖和以下程式碼模擬了細胞分裂的過程,時間複雜度為 $O(2^n)$
1123+
下圖和以下程式碼模擬了細胞分裂的過程,時間複雜度為 $O(2^n)$ 。請注意,輸入 $n$ 表示分裂輪數,返回值 `count` 表示總分裂次數。
11241124

11251125
```src
11261126
[file]{time_complexity}-[class]{}-[func]{exponential}

Diff for: zh-hant/docs/chapter_introduction/summary.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- 整理撲克的過程與插入排序演算法非常類似。插入排序演算法適合排序小型資料集。
66
- 貨幣找零的步驟本質上是貪婪演算法,每一步都採取當前看來最好的選擇。
77
- 演算法是在有限時間內解決特定問題的一組指令或操作步驟,而資料結構是計算機中組織和儲存資料的方式。
8-
- 資料結構與演算法緊密相連。資料結構是演算法的基石,而演算法是資料結構發揮作用的舞臺
8+
- 資料結構與演算法緊密相連。資料結構是演算法的基石,而演算法為資料結構注入生命力
99
- 我們可以將資料結構與演算法類比為拼裝積木,積木代表資料,積木的形狀和連線方式等代表資料結構,拼裝積木的步驟則對應演算法。
1010

1111
### Q & A

Diff for: zh-hant/docs/chapter_introduction/what_is_dsa.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
如下圖所示,資料結構與演算法高度相關、緊密結合,具體表現在以下三個方面。
2727

2828
- 資料結構是演算法的基石。資料結構為演算法提供了結構化儲存的資料,以及操作資料的方法。
29-
- 演算法是資料結構發揮作用的舞臺。資料結構本身僅儲存資料資訊,結合演算法才能解決特定問題。
29+
- 演算法為資料結構注入生命力。資料結構本身僅儲存資料資訊,結合演算法才能解決特定問題。
3030
- 演算法通常可以基於不同的資料結構實現,但執行效率可能相差很大,選擇合適的資料結構是關鍵。
3131

3232
![資料結構與演算法的關係](what_is_dsa.assets/relationship_between_data_structure_and_algorithm.png)

0 commit comments

Comments
 (0)