Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translation: optimize the translation of hash_map.md #1358

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

magentaqin
Copy link

If this pull request (PR) pertains to Chinese-to-English translation, please confirm that you have read the contribution guidelines and complete the checklist below:

  • This PR represents the translation of a single, complete document, or contains only bug fixes.
  • The translation accurately conveys the original meaning and intent of the Chinese version. If deviations exist, I have provided explanatory comments to clarify the reasons.

If this pull request (PR) is associated with coding or code transpilation, please attach the relevant console outputs to the PR and complete the following checklist:

  • I have thoroughly reviewed the code, focusing on its formatting, comments, indentation, and file headers.
  • I have confirmed that the code execution outputs are consistent with those produced by the reference code (Python or Java).
  • The code is designed to be compatible on standard operating systems, including Windows, macOS, and Ubuntu.

@krahets krahets changed the title feat: translate hash_map.md to English translation: optimize the translation of hash_map.md May 18, 2024
@krahets krahets added translation English translation documents documents-related labels May 18, 2024
Copy link
Owner

@krahets krahets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Please address the comments.

- **Deleting elements**: First, locate the element, then delete it from the array (or linked list), using $O(n)$ time.
- **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)$.
- **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)$.
- **Deleting an element**: In order to remove elements, we need to locate them first. Then, delete them from the array (or linked list). The time complexity of this operation is $O(n)$.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting a sentence with "Then, ..." is controversial (It's grammatically OK, but feels sudden/jarring). Just a style suggestion but maybe something like "To remove elements, we first need to locate them. After locating the elements, we delete them from the array (or linked list)..."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your suggestion. However, I think changing from "Then...." to duplicated words "locate..." might not be a good idea. How about something like "To remove elements, we first need to locate them. Subsequently, we delete..."?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that sounds better. Now that you moved the word "first" you can even revert to using "then" in the second sentence ("To remove elements, we first need to locate them. Then, we delete them from the array"). This sounds more natural to me at least. (We could also do singular "To remove an element, we first need to locate it. Then, we delete the element from the array"). Both of these sound smoother to me

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it sounds better. I've changed the sentence to singular form. Have a check. 8b39df2

Copy link
Contributor

@yuelinxin yuelinxin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider my suggestions, there are a few grammar errors that needs adjustment.

- **Adding elements**: Simply add the element to the end of the array (or linked list), using $O(1)$ time.
- **Querying elements**: Since the array (or linked list) is unordered, it requires traversing all the elements, using $O(n)$ time.
- **Deleting elements**: First, locate the element, then delete it from the array (or linked list), using $O(n)$ time.
- **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)$.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for simplicity, from line 11 to 13:
"Inserting an element" -> "Inserting elements"
"Searching for an element" -> "Searching elements"
"Deleting an element" -> "Deleting elements"


## Common operations of hash table

Common operations of a hash table include initialization, querying, adding key-value pairs, and deleting key-value pairs, etc. Example code is as follows:
The common operations of a hash table include: initialization, querying, adding key-value pairs, and deleting key-value pairs. Here is an example code:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in "The common operations", "The" is not needed, "Common operations of a ..." is more concise.


```shell
12836 % 100 = 36
20336 % 100 = 36
```

As shown in the figure below, both student numbers point to the same name, which is obviously incorrect. This situation where multiple inputs correspond to the same output is known as <u>hash collision</u>.
As shown in the figure below, both student IDs point to the same name, which is obviously incorrect. This situation where multiple inputs correspond to the same output is called as <u>hash collision</u>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"called as " -> "called", "called as" is not the correct syntax here.


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

Apart from hash tables, arrays and linked lists can also be used to implement querying functions. Their efficiency is compared in the table below.
In addition to hash tables, arrays and linked lists can also be used to implement query functionality, but the time complexity is different. The table below shows the comparison of time efficiency for common operations among them:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the original translation, also, "for common operations among them" is not a correct syntax.

@@ -1,30 +1,30 @@
# Hash table

A <u>hash table</u> achieves efficient element querying by establishing a mapping between keys and values. Specifically, when we input a `key` into the hash table, we can retrieve the corresponding `value` in $O(1)$ time.
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trailing "complexity" in this sentence is unnecessary, "in $O(1)$ time" is the more commonly used expression.


Observations reveal that **the time complexity for adding, deleting, and querying in a hash table is $O(1)$**, which is highly efficient.
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"It can be seen that" -> "The table shows that"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documents documents-related translation English translation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants