Skip to content

Commit e0d617e

Browse files
authored
translation: refine translation of hash_map.md (krahets#1483)
* Update hash_map.md * Update hash_map.md * Update hash_map.md to improve concise
1 parent 7a345fc commit e0d617e

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

en/docs/chapter_hashing/hash_map.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Hash table
22

3-
A <u>hash table</u>, also known as a <u>hash map</u>, is a data structure that establishes a mapping between keys and values, enabling efficient element retrieval. Specifically, when we input a `key` into the hash table, we can retrive the corresponding `value` in $O(1)$ time complexity.
3+
A <u>hash table</u>, also known as a <u>hash map</u>, is a data structure that establishes a mapping between keys and values, enabling efficient element retrieval. Specifically, when we input a `key` into the hash table, we can retrieve the corresponding `value` in $O(1)$ time complexity.
44

55
As shown in the figure below, given $n$ students, each student has two data fields: "Name" and "Student ID". If we want to implement a query function that takes a student ID as input and returns the corresponding name, we can use the hash table shown in the figure below.
66

77
![Abstract representation of a hash table](hash_map.assets/hash_table_lookup.png)
88

99
In addition to hash tables, arrays and linked lists can also be used to implement query functionality, but the time complexity is different. Their efficiency is compared in the table below:
1010

11-
- **Inserting elements**: Simply append the element to the tail of the array (or linked list). The time complexity of this operation is $O(1)$.
12-
- **Searching for elements**: As the array (or linked list) is unsorted, searching for an element requires traversing through all of the elements. The time complexity of this operation is $O(n)$.
13-
- **Deleting elements**: To remove an element, we first need to locate it. Then, we delete it from the array (or linked list). The time complexity of this operation is $O(n)$.
11+
- **Inserting an element**: Simply append the element to the tail of the array (or linked list). The time complexity of this operation is $O(1)$.
12+
- **Searching for an element**: As the array (or linked list) is unsorted, searching for an element requires traversing through all of the elements. The time complexity of this operation is $O(n)$.
13+
- **Deleting an element**: To remove an element, we first need to locate it. Then, we delete it from the array (or linked list). The time complexity of this operation is $O(n)$.
1414

1515
<p align="center"> Table <id> &nbsp; Comparison of time efficiency for common operations </p>
1616

@@ -20,7 +20,7 @@ In addition to hash tables, arrays and linked lists can also be used to implemen
2020
| Insert Elements | $O(1)$ | $O(1)$ | $O(1)$ |
2121
| Delete Elements | $O(n)$ | $O(n)$ | $O(1)$ |
2222

23-
It can be seen that **the time complexity for operations (insertion, deletion, searching, and modification) in a hash table is $O(1)$**, which is highly efficient.
23+
As observed, **the time complexity for operations (insertion, deletion, searching, and modification) in a hash table is $O(1)$**, which is highly efficient.
2424

2525
## Common operations of hash table
2626

@@ -56,7 +56,7 @@ Common operations of a hash table include: initialization, querying, adding key-
5656
unordered_map<int, string> map;
5757

5858
/* Add operation */
59-
// Add key-value pair (key, value) to the hash table
59+
// Add key-value pair (key, value) to hash table
6060
map[12836] = "Xiao Ha";
6161
map[15937] = "Xiao Luo";
6262
map[16750] = "Xiao Suan";
@@ -79,7 +79,7 @@ Common operations of a hash table include: initialization, querying, adding key-
7979
Map<Integer, String> map = new HashMap<>();
8080

8181
/* Add operation */
82-
// Add key-value pair (key, value) to the hash table
82+
// Add key-value pair (key, value) to hash table
8383
map.put(12836, "Xiao Ha");
8484
map.put(15937, "Xiao Luo");
8585
map.put(16750, "Xiao Suan");
@@ -101,7 +101,7 @@ Common operations of a hash table include: initialization, querying, adding key-
101101
/* Initialize hash table */
102102
Dictionary<int, string> map = new() {
103103
/* Add operation */
104-
// Add key-value pair (key, value) to the hash table
104+
// Add key-value pair (key, value) to hash table
105105
{ 12836, "Xiao Ha" },
106106
{ 15937, "Xiao Luo" },
107107
{ 16750, "Xiao Suan" },
@@ -125,7 +125,7 @@ Common operations of a hash table include: initialization, querying, adding key-
125125
hmap := make(map[int]string)
126126

127127
/* Add operation */
128-
// Add key-value pair (key, value) to the hash table
128+
// Add key-value pair (key, value) to hash table
129129
hmap[12836] = "Xiao Ha"
130130
hmap[15937] = "Xiao Luo"
131131
hmap[16750] = "Xiao Suan"
@@ -148,7 +148,7 @@ Common operations of a hash table include: initialization, querying, adding key-
148148
var map: [Int: String] = [:]
149149

150150
/* Add operation */
151-
// Add key-value pair (key, value) to the hash table
151+
// Add key-value pair (key, value) to hash table
152152
map[12836] = "Xiao Ha"
153153
map[15937] = "Xiao Luo"
154154
map[16750] = "Xiao Suan"
@@ -192,7 +192,7 @@ Common operations of a hash table include: initialization, querying, adding key-
192192
/* Initialize hash table */
193193
const map = new Map<number, string>();
194194
/* Add operation */
195-
// Add key-value pair (key, value) to the hash table
195+
// Add key-value pair (key, value) to hash table
196196
map.set(12836, 'Xiao Ha');
197197
map.set(15937, 'Xiao Luo');
198198
map.set(16750, 'Xiao Suan');
@@ -220,7 +220,7 @@ Common operations of a hash table include: initialization, querying, adding key-
220220
Map<int, String> map = {};
221221

222222
/* Add operation */
223-
// Add key-value pair (key, value) to the hash table
223+
// Add key-value pair (key, value) to hash table
224224
map[12836] = "Xiao Ha";
225225
map[15937] = "Xiao Luo";
226226
map[16750] = "Xiao Suan";
@@ -245,7 +245,7 @@ Common operations of a hash table include: initialization, querying, adding key-
245245
let mut map: HashMap<i32, String> = HashMap::new();
246246

247247
/* Add operation */
248-
// Add key-value pair (key, value) to the hash table
248+
// Add key-value pair (key, value) to hash table
249249
map.insert(12836, "Xiao Ha".to_string());
250250
map.insert(15937, "Xiao Luo".to_string());
251251
map.insert(16750, "Xiao Suan".to_string());
@@ -490,10 +490,10 @@ First, let's consider the simplest case: **implementing a hash table using only
490490

491491
So, how do we locate the corresponding bucket based on the `key`? This is achieved through a <u>hash function</u>. The role of the hash function is to map a larger input space to a smaller output space. In a hash table, the input space consists of all the keys, and the output space consists of all the buckets (array indices). In other words, given a `key`, **we can use the hash function to determine the storage location of the corresponding key-value pair in the array**.
492492

493-
When given a `key`, the calculation process of the hash function consists of the following two steps:
493+
With a given `key`, the calculation of the hash function consists of two steps:
494494

495495
1. Calculate the hash value by using a certain hash algorithm `hash()`.
496-
2. Take the modulus of the hash value with the bucket count (array length) `capacity` to obtain the array `index` corresponding to that key.
496+
2. Take the modulus of the hash value with the bucket count (array length) `capacity` to obtain the array `index` corresponding to the key.
497497

498498
```shell
499499
index = hash(key) % capacity

0 commit comments

Comments
 (0)