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: Update chapter_introduction/algorithms_are_everywhere.md #972

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions docs-en/chapter_introduction/algorithms_are_everywhere.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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 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.


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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
"Since $r$ comes after $m$ alphabetically, we exclude the first half of the dictionary and narrow the search to the second half."

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)
Expand All @@ -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$.
Expand All @@ -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.