From ff8e7ceec50bc4198c90287e23b384e75d9f6c7f Mon Sep 17 00:00:00 2001 From: krahets Date: Sun, 24 Sep 2023 20:38:21 +0800 Subject: [PATCH] Several bug fixes. --- codes/c/chapter_hashing/hash_map_chaining.c | 2 +- codes/cpp/chapter_hashing/hash_map_chaining.cpp | 2 +- codes/cpp/chapter_hashing/hash_map_open_addressing.cpp | 2 +- codes/csharp/chapter_hashing/hash_map_chaining.cs | 2 +- codes/csharp/chapter_hashing/hash_map_open_addressing.cs | 2 +- codes/dart/chapter_hashing/hash_map_chaining.dart | 2 +- codes/go/chapter_hashing/hash_map_chaining.go | 2 +- codes/go/chapter_hashing/hash_map_open_addressing.go | 2 +- codes/java/chapter_hashing/hash_map_chaining.java | 2 +- codes/java/chapter_hashing/hash_map_open_addressing.java | 2 +- codes/javascript/chapter_hashing/hash_map_chaining.js | 2 +- codes/python/chapter_hashing/hash_map_chaining.py | 2 +- codes/python/chapter_hashing/hash_map_open_addressing.py | 2 +- codes/swift/chapter_hashing/hash_map_chaining.swift | 2 +- codes/swift/chapter_hashing/hash_map_open_addressing.swift | 2 +- codes/typescript/chapter_hashing/hash_map_chaining.ts | 2 +- .../chapter_computational_complexity/iteration_and_recursion.md | 2 +- docs/chapter_hashing/hash_collision.md | 2 +- docs/chapter_preface/about_the_book.md | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/codes/c/chapter_hashing/hash_map_chaining.c b/codes/c/chapter_hashing/hash_map_chaining.c index de8cb11fb..94e7202e0 100644 --- a/codes/c/chapter_hashing/hash_map_chaining.c +++ b/codes/c/chapter_hashing/hash_map_chaining.c @@ -48,7 +48,7 @@ hashMapChaining *newHashMapChaining() { hashmap->capacity = tableSize; hashmap->size = 0; hashmap->extendRatio = 2; - hashmap->loadThres = 2.0 / 3; + hashmap->loadThres = 2.0 / 3.0; return hashmap; } diff --git a/codes/cpp/chapter_hashing/hash_map_chaining.cpp b/codes/cpp/chapter_hashing/hash_map_chaining.cpp index a61703724..2302f0c0d 100644 --- a/codes/cpp/chapter_hashing/hash_map_chaining.cpp +++ b/codes/cpp/chapter_hashing/hash_map_chaining.cpp @@ -17,7 +17,7 @@ class HashMapChaining { public: /* 构造方法 */ - HashMapChaining() : size(0), capacity(4), loadThres(2.0 / 3), extendRatio(2) { + HashMapChaining() : size(0), capacity(4), loadThres(2.0 / 3.0), extendRatio(2) { buckets.resize(capacity); } diff --git a/codes/cpp/chapter_hashing/hash_map_open_addressing.cpp b/codes/cpp/chapter_hashing/hash_map_open_addressing.cpp index ef39aecf9..4c411fb48 100644 --- a/codes/cpp/chapter_hashing/hash_map_open_addressing.cpp +++ b/codes/cpp/chapter_hashing/hash_map_open_addressing.cpp @@ -11,7 +11,7 @@ class HashMapOpenAddressing { private: int size; // 键值对数量 int capacity = 4; // 哈希表容量 - const double loadThres = 2.0 / 3; // 触发扩容的负载因子阈值 + const double loadThres = 2.0 / 3.0; // 触发扩容的负载因子阈值 const int extendRatio = 2; // 扩容倍数 vector buckets; // 桶数组 Pair *TOMBSTONE = new Pair(-1, "-1"); // 删除标记 diff --git a/codes/csharp/chapter_hashing/hash_map_chaining.cs b/codes/csharp/chapter_hashing/hash_map_chaining.cs index a05edf574..39270333a 100644 --- a/codes/csharp/chapter_hashing/hash_map_chaining.cs +++ b/codes/csharp/chapter_hashing/hash_map_chaining.cs @@ -18,7 +18,7 @@ class HashMapChaining { public HashMapChaining() { size = 0; capacity = 4; - loadThres = 2 / 3.0; + loadThres = 2.0 / 3.0; extendRatio = 2; buckets = new List>(capacity); for (int i = 0; i < capacity; i++) { diff --git a/codes/csharp/chapter_hashing/hash_map_open_addressing.cs b/codes/csharp/chapter_hashing/hash_map_open_addressing.cs index e9f062d75..b41a2621d 100644 --- a/codes/csharp/chapter_hashing/hash_map_open_addressing.cs +++ b/codes/csharp/chapter_hashing/hash_map_open_addressing.cs @@ -10,7 +10,7 @@ namespace hello_algo.chapter_hashing; class HashMapOpenAddressing { private int size; // 键值对数量 private int capacity = 4; // 哈希表容量 - private double loadThres = 2.0 / 3; // 触发扩容的负载因子阈值 + private double loadThres = 2.0 / 3.0; // 触发扩容的负载因子阈值 private int extendRatio = 2; // 扩容倍数 private Pair[] buckets; // 桶数组 private Pair TOMBSTONE = new Pair(-1, "-1"); // 删除标记 diff --git a/codes/dart/chapter_hashing/hash_map_chaining.dart b/codes/dart/chapter_hashing/hash_map_chaining.dart index 1804ab7e8..fcf3ab0d2 100644 --- a/codes/dart/chapter_hashing/hash_map_chaining.dart +++ b/codes/dart/chapter_hashing/hash_map_chaining.dart @@ -23,7 +23,7 @@ class HashMapChaining { HashMapChaining() { size = 0; capacity = 4; - loadThres = 2 / 3.0; + loadThres = 2.0 / 3.0; extendRatio = 2; buckets = List.generate(capacity, (_) => []); } diff --git a/codes/go/chapter_hashing/hash_map_chaining.go b/codes/go/chapter_hashing/hash_map_chaining.go index c0b59ea73..201674090 100644 --- a/codes/go/chapter_hashing/hash_map_chaining.go +++ b/codes/go/chapter_hashing/hash_map_chaining.go @@ -28,7 +28,7 @@ func newHashMapChaining() *hashMapChaining { return &hashMapChaining{ size: 0, capacity: 4, - loadThres: 2 / 3.0, + loadThres: 2.0 / 3.0, extendRatio: 2, buckets: buckets, } diff --git a/codes/go/chapter_hashing/hash_map_open_addressing.go b/codes/go/chapter_hashing/hash_map_open_addressing.go index a03017993..4db637e6c 100644 --- a/codes/go/chapter_hashing/hash_map_open_addressing.go +++ b/codes/go/chapter_hashing/hash_map_open_addressing.go @@ -25,7 +25,7 @@ func newHashMapOpenAddressing() *hashMapOpenAddressing { return &hashMapOpenAddressing{ size: 0, capacity: 4, - loadThres: 2 / 3.0, + loadThres: 2.0 / 3.0, extendRatio: 2, buckets: buckets, removed: pair{ diff --git a/codes/java/chapter_hashing/hash_map_chaining.java b/codes/java/chapter_hashing/hash_map_chaining.java index 9f77421af..9133ef02b 100644 --- a/codes/java/chapter_hashing/hash_map_chaining.java +++ b/codes/java/chapter_hashing/hash_map_chaining.java @@ -21,7 +21,7 @@ class HashMapChaining { public HashMapChaining() { size = 0; capacity = 4; - loadThres = 2 / 3.0; + loadThres = 2.0 / 3.0; extendRatio = 2; buckets = new ArrayList<>(capacity); for (int i = 0; i < capacity; i++) { diff --git a/codes/java/chapter_hashing/hash_map_open_addressing.java b/codes/java/chapter_hashing/hash_map_open_addressing.java index b8176bf5f..4e1534b58 100644 --- a/codes/java/chapter_hashing/hash_map_open_addressing.java +++ b/codes/java/chapter_hashing/hash_map_open_addressing.java @@ -10,7 +10,7 @@ package chapter_hashing; class HashMapOpenAddressing { private int size; // 键值对数量 private int capacity = 4; // 哈希表容量 - private final double loadThres = 2.0 / 3; // 触发扩容的负载因子阈值 + private final double loadThres = 2.0 / 3.0; // 触发扩容的负载因子阈值 private final int extendRatio = 2; // 扩容倍数 private Pair[] buckets; // 桶数组 private final Pair TOMBSTONE = new Pair(-1, "-1"); // 删除标记 diff --git a/codes/javascript/chapter_hashing/hash_map_chaining.js b/codes/javascript/chapter_hashing/hash_map_chaining.js index 151cb5a57..6f1276f15 100644 --- a/codes/javascript/chapter_hashing/hash_map_chaining.js +++ b/codes/javascript/chapter_hashing/hash_map_chaining.js @@ -24,7 +24,7 @@ class HashMapChaining { constructor() { this.#size = 0; this.#capacity = 4; - this.#loadThres = 2 / 3.0; + this.#loadThres = 2.0 / 3.0; this.#extendRatio = 2; this.#buckets = new Array(this.#capacity).fill(null).map((x) => []); } diff --git a/codes/python/chapter_hashing/hash_map_chaining.py b/codes/python/chapter_hashing/hash_map_chaining.py index 96769eb5e..069d43a53 100644 --- a/codes/python/chapter_hashing/hash_map_chaining.py +++ b/codes/python/chapter_hashing/hash_map_chaining.py @@ -17,7 +17,7 @@ class HashMapChaining: """构造方法""" self.size = 0 # 键值对数量 self.capacity = 4 # 哈希表容量 - self.load_thres = 2 / 3 # 触发扩容的负载因子阈值 + self.load_thres = 2.0 / 3.0 # 触发扩容的负载因子阈值 self.extend_ratio = 2 # 扩容倍数 self.buckets = [[] for _ in range(self.capacity)] # 桶数组 diff --git a/codes/python/chapter_hashing/hash_map_open_addressing.py b/codes/python/chapter_hashing/hash_map_open_addressing.py index 9ecefe863..475859038 100644 --- a/codes/python/chapter_hashing/hash_map_open_addressing.py +++ b/codes/python/chapter_hashing/hash_map_open_addressing.py @@ -17,7 +17,7 @@ class HashMapOpenAddressing: """构造方法""" self.size = 0 # 键值对数量 self.capacity = 4 # 哈希表容量 - self.load_thres = 2 / 3 # 触发扩容的负载因子阈值 + self.load_thres = 2.0 / 3.0 # 触发扩容的负载因子阈值 self.extend_ratio = 2 # 扩容倍数 self.buckets: list[Pair | None] = [None] * self.capacity # 桶数组 self.TOMBSTONE = Pair(-1, "-1") # 删除标记 diff --git a/codes/swift/chapter_hashing/hash_map_chaining.swift b/codes/swift/chapter_hashing/hash_map_chaining.swift index abeebd1ee..7d88f78be 100644 --- a/codes/swift/chapter_hashing/hash_map_chaining.swift +++ b/codes/swift/chapter_hashing/hash_map_chaining.swift @@ -18,7 +18,7 @@ class HashMapChaining { init() { size = 0 capacity = 4 - loadThres = 2 / 3 + loadThres = 2.0 / 3.0 extendRatio = 2 buckets = Array(repeating: [], count: capacity) } diff --git a/codes/swift/chapter_hashing/hash_map_open_addressing.swift b/codes/swift/chapter_hashing/hash_map_open_addressing.swift index 9b26128d8..53e01da24 100644 --- a/codes/swift/chapter_hashing/hash_map_open_addressing.swift +++ b/codes/swift/chapter_hashing/hash_map_open_addressing.swift @@ -19,7 +19,7 @@ class HashMapOpenAddressing { init() { size = 0 capacity = 4 - loadThres = 2 / 3 + loadThres = 2.0 / 3.0 extendRatio = 2 buckets = Array(repeating: nil, count: capacity) removed = Pair(key: -1, val: "-1") diff --git a/codes/typescript/chapter_hashing/hash_map_chaining.ts b/codes/typescript/chapter_hashing/hash_map_chaining.ts index 3da27403e..51a59b636 100644 --- a/codes/typescript/chapter_hashing/hash_map_chaining.ts +++ b/codes/typescript/chapter_hashing/hash_map_chaining.ts @@ -26,7 +26,7 @@ class HashMapChaining { constructor() { this.#size = 0; this.#capacity = 4; - this.#loadThres = 2 / 3.0; + this.#loadThres = 2.0 / 3.0; this.#extendRatio = 2; this.#buckets = new Array(this.#capacity).fill(null).map((x) => []); } diff --git a/docs/chapter_computational_complexity/iteration_and_recursion.md b/docs/chapter_computational_complexity/iteration_and_recursion.md index 7a4e2393a..62767d8a8 100644 --- a/docs/chapter_computational_complexity/iteration_and_recursion.md +++ b/docs/chapter_computational_complexity/iteration_and_recursion.md @@ -429,7 +429,7 @@ 以上述的求和函数为例,设问题 $f(n) = 1 + 2 + \dots + n$ 。 - **迭代**:在循环中模拟求和过程,从 $1$ 遍历到 $n$ ,每轮执行求和操作,即可求得 $f(n)$ 。 -- **递归**:将问题分解为子问题 $f(n) = n + f(n-1)$ ,不断(递归地)分解下去,直至基本情况 $f(0) = 0$ 时终止。 +- **递归**:将问题分解为子问题 $f(n) = n + f(n-1)$ ,不断(递归地)分解下去,直至基本情况 $f(1) = 1$ 时终止。 ### 调用栈 diff --git a/docs/chapter_hashing/hash_collision.md b/docs/chapter_hashing/hash_collision.md index 3d076926f..90124c450 100644 --- a/docs/chapter_hashing/hash_collision.md +++ b/docs/chapter_hashing/hash_collision.md @@ -29,7 +29,7 @@ 以下代码给出了链式地址哈希表的简单实现,需要注意两点。 - 使用列表(动态数组)代替链表,从而简化代码。在这种设定下,哈希表(数组)包含多个桶,每个桶都是一个列表。 -- 以下实现包含哈希表扩容方法。当负载因子超过 $0.75$ 时,我们将哈希表扩容至 $2$ 倍。 +- 以下实现包含哈希表扩容方法。当负载因子超过 $\frac{2}{3}$ 时,我们将哈希表扩容至 $2$ 倍。 === "Python" diff --git a/docs/chapter_preface/about_the_book.md b/docs/chapter_preface/about_the_book.md index 147cd0818..3d4880574 100644 --- a/docs/chapter_preface/about_the_book.md +++ b/docs/chapter_preface/about_the_book.md @@ -26,7 +26,7 @@ - **数据结构**:基本数据类型,数据结构的分类方法。数组、链表、栈、队列、哈希表、树、堆、图等数据结构的定义、优缺点、常用操作、常见类型、典型应用、实现方法等。 - **算法**:搜索、排序、分治、回溯、动态规划、贪心等算法的定义、优缺点、效率、应用场景、解题步骤、示例题目等。 -![Hello 算法内容结构](about_the_book.assets/hello_algo_mindmap.png) +![Hello 算法内容结构](about_the_book.assets/hello_algo_mindmap.jpg) ## 致谢