Skip to content

translation: Update algorithms_are_everywhere.md #1733

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
50 changes: 25 additions & 25 deletions en/docs/chapter_introduction/algorithms_are_everywhere.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
# Algorithms are everywhere

When we hear the word "algorithm," we naturally think of mathematics. However, many algorithms do not involve complex mathematics but rely more on basic logic, which can be seen everywhere in our daily lives.
When we hear the term "algorithm," we naturally think of mathematics. However, many algorithms do not involve complex mathematics but rely more on basic logic, which can be seen everywhere in our daily lives.

Before formally discussing algorithms, there's an interesting fact worth sharing: **you have already unconsciously learned many algorithms and have become accustomed to applying them in your daily life**. Here, I will give a few specific examples to prove this point.
Before we start discussing about algorithms officially, there's an interesting fact worth sharing: **you've learned many algorithms unconsciously and are used to applying them in your daily life**. Here, I will give a few specific examples to prove this point.

**Example 1: Looking Up a Dictionary**. In an English dictionary, words are listed alphabetically. Suppose we're searching for a word that starts with the letter $r$. This is typically done in the following way:
**Example 1: Looking Up a Dictionary**. In an English dictionary, words are listed alphabetically. Assuming we're searching for a word that starts 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, let's say the letter is $m$.
2. Since $r$ comes after $m$ in the alphabet, we can ignore the first half of the dictionary and focus on the latter half.
1. Open the dictionary to about halfway and check the first vocabulary of the page, let's say the letter starts with $m$.
Copy link
Contributor

@yanedie yanedie Apr 28, 2025

Choose a reason for hiding this comment

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

"vocabulary" -> "letter". "starts with" > "is".
The Chinese is "首字母", which is the first letter. Dictionaries arrange words from A to Z. We need to locate the first letter of the target word.

Reference:
https://www.wikihow.com/Use-a-Dictionary Part 2 Looking Up a Word

Copy link
Author

@beatrix-chan beatrix-chan Apr 28, 2025

Choose a reason for hiding this comment

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

To clarify, are we checking for the first complete word in the list, or the first letter of the first word on the page?

E.g. The list is ['apple', 'banana', 'corn'], are we checking for apple or are we checking for a?

For your reference:
Vocabulary vs. Word - What's the Difference?

2. Since $r$ comes after $m$ in the alphabet, the first half can be ignored and the search space is narrowed down to the second half.
3. Repeat steps `1.` and `2.` until you find the page where the word starts with $r$.

=== "<1>"
![Process of Looking Up a Dictionary](algorithms_are_everywhere.assets/binary_search_dictionary_step1.png)
![First Step of Looking Up a Dictionary](algorithms_are_everywhere.assets/binary_search_dictionary_step1.png)

=== "<2>"
![Binary Search in Dictionary Step 2](algorithms_are_everywhere.assets/binary_search_dictionary_step2.png)
![Second Step of Looking Up a Dictionary](algorithms_are_everywhere.assets/binary_search_dictionary_step2.png)

=== "<3>"
![Binary Search in Dictionary Step 3](algorithms_are_everywhere.assets/binary_search_dictionary_step3.png)
![Third Step of Looking Up a Dictionary](algorithms_are_everywhere.assets/binary_search_dictionary_step3.png)

=== "<4>"
![Binary Search in Dictionary Step 4](algorithms_are_everywhere.assets/binary_search_dictionary_step4.png)
![Fourth Step of Looking Up a Dictionary](algorithms_are_everywhere.assets/binary_search_dictionary_step4.png)

=== "<5>"
![Binary Search in Dictionary Step 5](algorithms_are_everywhere.assets/binary_search_dictionary_step5.png)
![Fifth Step of Looking Up a Dictionary](algorithms_are_everywhere.assets/binary_search_dictionary_step5.png)

This essential skill for elementary students, looking up a dictionary, is actually the famous "Binary Search" algorithm. From a data structure perspective, we can consider the dictionary as a sorted "array"; from an algorithmic perspective, the series of actions taken to look up a word in the dictionary can be viewed as "Binary Search."
Looking up a dictionary, an essential skill for elementary school students is actually the famous "Binary Search" algorithm. From a data structure perspective, we can consider the dictionary as a sorted "array"; from an algorithmic perspective, the series of actions taken to look up a word in the dictionary can be viewed as the algorithm "Binary Search."

**Example 2: Organizing Playing Cards**. When playing cards, we need to arrange the cards in our hand in ascending order, as shown in the following process.
**Example 2: Organizing Card Deck**. When playing cards, we need to arrange the cards in our hands in ascending order, as shown in the following process.

1. Divide the playing cards into "ordered" and "unordered" sections, assuming initially the leftmost card is already in order.
2. Take out a card from the unordered section and insert it into the correct position in the ordered section; after this, the leftmost two cards are in order.
1. Divide the deck of cards into "ordered" and "unordered" sections, assuming the leftmost card is already "ordered".
2. Remove a card from the "unordered" section and place it in the correct position within the "ordered" section; after this step, the leftmost two cards will be in order.
3. Continue to repeat step `2.` until all cards are in order.

![Playing cards sorting process](algorithms_are_everywhere.assets/playing_cards_sorting.png)
![Process of Sorting a Deck of Cards](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 functions include the insertion sort.
The above method of organizing playing cards is practically the "Insertion Sort" algorithm, which is very efficient for small datasets. Many programming languages' sorting functions include the insertion sort.

**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 in the figure below.
**Example 3: Making Change**. Imagine purchasing items costing $\$69$ at a supermarket. If you give the cashier $\$100$, they will need to provide you with $\$31$ in change. This process can be clearly understood as illustrated in the figure below.
Copy link
Contributor

Choose a reason for hiding this comment

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

Imagine > Assuming

Copy link
Author

@beatrix-chan beatrix-chan Apr 28, 2025

Choose a reason for hiding this comment

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

Now that I've reread this sentence, it sounds a bit awkward. Would "Assume making a purchase of $69 at a supermarket..." sound more fluent?


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$.
3. Take out the largest $10$ from the remaining options, leaving $11 - 10 = 1$.
4. Take out the largest $1$ from the remaining options, leaving $1 - 1 = 0$.
5. Complete the change-making, with the solution being $20 + 10 + 1 = 31$.
1. The options are currencies valued below $\$31$, including $\$1$, $\$5$, $\$10$, and $\$20$.
2. Take out the largest $\$20$ from the options, leaving $\$31 - \$20 = \$11$.
3. Take out the largest $\$10$ from the remaining options, leaving $\$11 - \$10 = \$1$.
4. Take out the largest $\$1$ from the remaining options, leaving $\$1 - \$1 = \$0$.
5. Complete change-making, the solution is $\$20 + \$10 + \$1 = \$31$.

![Change making process](algorithms_are_everywhere.assets/greedy_change.png)
![Process of making change](algorithms_are_everywhere.assets/greedy_change.png)

In the above steps, we make the best choice at each step (using the largest denomination possible), ultimately resulting in a feasible change-making plan. From the perspective of data structures and algorithms, this method is essentially a "Greedy" algorithm.
In the steps described, we choose the best option at each stage by utilizing the largest denomination available, which leads to an effective change-making strategy. From a data structures and algorithms perspective, this approach is known as a "Greedy" algorithm.

From cooking a meal to interstellar travel, almost all problem-solving involves algorithms. The advent of computers allows us to store data structures in memory and write code to call the CPU and GPU to execute algorithms. In this way, we can transfer real-life problems to computers, solving various complex issues more efficiently.

!!! tip

If concepts such as data structures, algorithms, arrays, and binary search still seem somewhat obscure, I encourage you to continue reading. This book will gently guide you into the realm of understanding data structures and algorithms.
If you are still confused about concepts like data structures, algorithms, arrays, and binary searches, I encourage you to keep reading. This book will gently guide you into the realm of understanding data structures and algorithms.