-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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: Update chapter_introduction/algorithms_are_everywhere.md #972
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,11 @@ When we hear the word "algorithm", we naturally think of mathematics. However, m | |
|
||
Before we formally discuss algorithms, an interesting fact is worth sharing: **you have already learned many algorithms unconsciously and have become accustomed to applying them in your daily life**. Below, I will give a few specific examples to prove this point. | ||
|
||
**Example 1: Looking Up a Dictionary**. In a dictionary, each Chinese character corresponds to a pinyin, and the dictionary is arranged in alphabetical order of pinyin. Suppose we need to find a character whose pinyin starts with the letter $r$. This is usually achieved in the following way: | ||
**Example 1: Looking Up a Dictionary**. In a standard dictionary, each word corresponds to a phonetic transcription and the dictionary is organized alphabetically based on these transcriptions. Let's say we're looking for a word that begins with the letter $r$. This is typically done in the following way: | ||
|
||
1. Open the dictionary to about halfway and check the first letter on the page, assuming it is $m$. | ||
2. Since $r$ comes after $m$ in the pinyin alphabet, we exclude the first half of the dictionary and narrow the search to the second half. | ||
3. Repeat steps `1.` and `2.` until you find the page where the pinyin starts with $r$. | ||
1. Open the dictionary around its midpoint and note the first letter on that page, assuming it to be $m$. | ||
2. Given the sequence of words following the initial letter $m$, estimate where words starting with the letter $r$ might be located within the alphabetical order. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should stick to the original reasoning here, it makes more sense. |
||
3. Iterate steps `1.` and `2.` until you find the page where the word begins with the letter $r$. | ||
|
||
=== "<1>" | ||
![Dictionary search step](algorithms_are_everywhere.assets/binary_search_dictionary_step1.png) | ||
|
@@ -25,19 +25,19 @@ Before we formally discuss algorithms, an interesting fact is worth sharing: **y | |
=== "<5>" | ||
![binary_search_dictionary_step5](algorithms_are_everywhere.assets/binary_search_dictionary_step5.png) | ||
|
||
The skill of looking up a dictionary, essential for elementary school students, is actually the famous binary search algorithm. From the perspective of data structures, we can view the dictionary as a sorted "array"; from the perspective of algorithms, the series of operations in looking up a dictionary can be seen as "binary search". | ||
The skill of looking up a dictionary, essential for elementary school students, is actually the renowned binary search algorithm. Through the lens of data structures, we can view the dictionary as a sorted "array"; while from an algorithmic perspective, the series of operations in looking up a dictionary can be seen as "binary search". | ||
|
||
**Example 2: Organizing Playing Cards**. When playing cards, we need to arrange the cards in ascending order each game, as shown in the following process. | ||
|
||
1. Divide the playing cards into "ordered" and "unordered" parts, assuming initially that the leftmost card is already ordered. | ||
2. Take out a card from the unordered part and insert it into the correct position in the ordered part; after this, the leftmost two cards are in order. | ||
3. Continue looping step `2.`, each round inserting one card from the unordered part into the ordered part, until all cards are ordered. | ||
2. Take out a card from the unordered part and insert it into the correct position in the ordered part; once completed, the leftmost two cards will be in an ordered sequence. | ||
3. Continue the loop described in step `2.`, each iteration involving insertion of one card from the unordered segment into the ordered portion, until all cards are appropriately ordered. | ||
|
||
![Playing cards sorting process](algorithms_are_everywhere.assets/playing_cards_sorting.png) | ||
|
||
The above method of organizing playing cards is essentially the "insertion sort" algorithm, which is very efficient for small datasets. Many programming languages' sorting library functions include insertion sort. | ||
|
||
**Example 3: Making Change**. Suppose we buy goods worth $69$ at a supermarket and give the cashier $100$, then the cashier needs to give us $31$ in change. They would naturally complete the thought process as shown below. | ||
**Example 3: Making Change**. Suppose we buy goods worth $69$ yuan at a supermarket and give the cashier $100$ yuan, then the cashier needs to give us $31$ yuan in change. They would naturally complete the thought process as shown below. | ||
|
||
1. The options are currencies smaller than $31$, including $1$, $5$, $10$, and $20$. | ||
2. Take out the largest $20$ from the options, leaving $31 - 20 = 11$. | ||
|
@@ -47,10 +47,10 @@ The above method of organizing playing cards is essentially the "insertion sort" | |
|
||
![Change making process](algorithms_are_everywhere.assets/greedy_change.png) | ||
|
||
In the steps above, we make the best choice at each step (using the largest denomination possible), ultimately arriving at a feasible change-making solution. From the perspective of data structures and algorithms, this method is essentially a "greedy" algorithm. | ||
In the aforementioned steps, at each stage, we make the optimal choice (utilizing the highest denomination possible), ultimately deriving at a feasible change-making approach. From the perspective of data structures and algorithms, this approach is essentially a "greedy" algorithm. | ||
|
||
From cooking a dish to interstellar travel, almost all problem-solving is inseparable from algorithms. The advent of computers allows us to store data structures in memory and write code to call CPUs and GPUs to execute algorithms. In this way, we can transfer problems from life to computers, solving various complex issues more efficiently. | ||
From preparing a dish to traversing interstellar realms, virtually every problem-solving endeavor relies on algorithms. The emergence of computers enables us to store data structures in memory and write code to call CPUs and GPUs to execute algorithms. Consequently, we can transfer real-life predicaments to computers, efficiently addressing a myriad of complex issues. | ||
|
||
!!! tip | ||
|
||
If you still feel only partially informed about concepts like data structures, algorithms, arrays, and binary search, please continue reading. This book will guide you into the hall of knowledge of data structures and algorithms. | ||
If concepts such as data structures, algorithms, arrays, and binary search still seem somewhat obsecure, I encourage you to continue reading. This book will gently guide you into the realm of understanding data structures and algorithms. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of the difference between different languages, there's no need to stick that close to the original text, simply stating that in an English dictionary, the words are listed alphabetically is sufficient. Adding this "phonetic transcription" bit just adds more confusion.