Standard algorithms · 标准算法
| English | 中文 | Pinyin · 拼音 |
|---|---|---|
| linear search/ˈlɪnɪə sɜːtʃ/ | 线性查找 | xiàn xìng chá zhǎo |
| bubble sort/ˈbʌbl sɔːt/ | 冒泡排序 | mào pào pái xù |
| counting/ˈkaʊntɪŋ/ | 计数 | jì shù |
| totalling/ˈtəʊtəlɪŋ/ | 求和 | qiú hé |
The classic recipes
- A few standard algorithms appear again and again.
- You must know linear search 线性查找, bubble sort 冒泡排序, and the counting 计数/totalling 求和 patterns.
- Each is short, but worth recognising instantly.
经典的配方
- 几个标准算法一再出现。
- 你必须知道线性搜索(linear search)、冒泡排序(bubble sort),以及计数/求和模式。
- 每个都很短,但值得立刻认出。
Linear search
- A linear search checks each item in turn, from the start, until it finds the value (or reaches the end).
- It works on any list — no sorting needed.
A flowchart for the sum algorithm, using the standard symbols (start/end, input/output, process, decision).
线性搜索
DECLARE Found : BOOLEAN
Found ← FALSE
FOR I ← 1 TO 10
IF List[I] = SearchValue
THEN
Found ← TRUE
ENDIF
NEXT I
OUTPUT Found
- 一个线性搜索从开始依次检查每个项目,直到找到这个值(或到达末尾)。
- 它在任何列表上有效——不需要排序。

求和算法的一张流程图,使用标准符号(开始/结束、输入/输出、处理、判断)。
Standard algorithms · 标准算法
compare adjacent, swap if needed · 比较相邻的,需要时交换
Step through a bubble sort — compare neighbours and swap until everything is in order. · 逐步看一个冒泡排序——比较邻居并交换,直到一切都排好序。
A linear search finds a value by: · 一个线性搜索通过以下找到一个值:
Linear search examines items one by one until it finds the value or reaches the end. · 线性搜索一个接一个地检查项目,直到找到这个值或到达末尾。
Bubble sort
- A bubble sort compares each side-by-side pair and swaps them if they are out of order.
- It repeats this until no more swaps are needed — leaving the list sorted.
Bubble sort compares each side-by-side pair and swaps them if they are out of order, repeating until sorted.
冒泡排序
FOR I ← 0 TO 8
IF List[I] > List[I + 1]
THEN
Temp ← List[I]
List[I] ← List[I + 1]
List[I + 1] ← Temp
ENDIF
NEXT I
- 一个冒泡排序比较每个并排的对,如果它们顺序不对就交换它们。
- 它重复这个直到不再需要交换——使列表排好序。

冒泡排序比较每个并排的对,如果它们顺序不对就交换它们,重复直到排好序。
A bubble sort puts a list in order by: · 一个冒泡排序通过以下给一个列表排序:
It swaps out-of-order neighbours and repeats passes until no swaps are needed. · 它交换顺序不对的邻居并重复遍历,直到不需要交换。
Totalling, counting, max/min/average
- Totalling — keep a running total:
Total ← Total + Value. - Counting — add 1 each time something happens:
Count ← Count + 1. - Maximum/minimum — keep the largest/smallest value seen so far.
- Average — divide the total by how many values there are.
求和、计数、最大/最小/平均
- 求和(totalling)——保持一个运行总和:
Total ← Total + Value。 - 计数(counting)——每次某事发生时加 1:
Count ← Count + 1。 - 最大/最小(maximum/minimum)——保持目前为止看到的最大/最小值。
- 平均(average)——用总和除以有多少个值。
Which line adds a value to a running total? · 哪一行把一个值加到一个运行总和?
total ← total + value accumulates a sum; count ← count + 1 counts occurrences. · total ← total + value 累积一个和;count ← count + 1 计数出现次数。
Match each standard algorithm to how it works. · 把每个标准算法匹配到它如何工作。
These four — search, sort, total and max — are the building blocks of most exam algorithms. · 这四个——搜索、排序、求和和最大——是大多数考试算法的构建块。
Using totalling on the list [2, 4, 6, 8], what is the final total? · 在列表 [2, 4, 6, 8] 上使用求和,最终总和是多少?
2 + 4 + 6 + 8 = 20. · 2 + 4 + 6 + 8 = 20。
You've got it
- linear search checks each item in turn (works on any list)
- bubble sort swaps out-of-order neighbours, repeating until sorted
- totalling (
Total ← Total + Value) and counting (Count ← Count + 1) - max/min = keep the best so far; average = total ÷ count
你掌握了
- 线性搜索依次检查每个项目(在任何列表上有效)
- 冒泡排序交换顺序不对的邻居,重复直到排好序
- 求和(
Total ← Total + Value)和计数(Count ← Count + 1) - 最大/最小 = 保持目前为止最好的;平均 = 总和 ÷ 计数