📚 KS3 Maths: Algorithms Explained | KS3 数学:算法考点精讲
Algorithms are the backbone of problem-solving in mathematics and computer science. At KS3, you will learn to design, follow and evaluate step-by-step procedures to solve problems efficiently. This revision guide covers the key concepts you need: what an algorithm is, how to represent it with flowcharts and pseudocode, and essential searching and sorting algorithms. You will also see how mathematical ideas like finding the highest common factor can be turned into a clear algorithm. Mastering these fundamentals will build your confidence in logical thinking and prepare you for more advanced topics.
算法是数学和计算机科学中解决问题的核心。在 KS3 阶段,你将学习设计、执行和评估一步步解决问题的过程。本精讲涵盖你需要掌握的关键概念:算法的定义、用流程图和伪代码表示算法的方法,以及基本的搜索和排序算法。你还会看到如何把求最大公约数这样的数学问题转化为明确的算法。掌握这些基础将增强你的逻辑思维能力,并为更高级的主题做好准备。
1. What is an Algorithm? | 什么是算法?
An algorithm is a precise, step-by-step set of instructions designed to solve a problem or carry out a task. In mathematics, you follow algorithms all the time—for example, when you do long division or add fractions by finding a common denominator. An algorithm must have a clear start and end, and each step must be unambiguous so that anyone (or any computer) can follow it and get the same result.
算法是一组精确的、逐步设计的指令,用于解决问题或执行任务。在数学中,你一直在使用算法——例如,做长除法或通过找公分母来加分数。算法必须有明确的开始和结束,每一步都必须无歧义,这样任何人(或任何计算机)都能遵循它并得到相同的结果。
Key properties of a good algorithm:
好算法的关键特性:
- Clear and precise – no vague instructions.
清晰精确 – 没有含糊的指令。 - Finite – it always ends after a certain number of steps.
有限性 – 它总是在执行完有限步后结束。 - Effective – each step can be carried out in a reasonable time.
有效性 – 每一步都能在合理的时间内完成。 - Input and output – it usually takes some data and produces a result.
输入与输出 – 它通常接受一些数据并产生结果。
In KS3, you are expected to design simple algorithms for arithmetic tasks and understand the logic behind everyday processes, like following a recipe or sorting playing cards.
在 KS3 阶段,你需要为算术任务设计简单的算法,并理解日常过程(如遵循食谱或整理扑克牌)背后的逻辑。
2. Representing Algorithms: Flowcharts and Pseudocode | 算法的表示:流程图与伪代码
Before writing a program, we often plan an algorithm using two common methods: flowcharts and pseudocode. A flowchart uses symbols and arrows to show the flow of control visually, while pseudocode describes the steps in plain but structured English.
在编写程序之前,我们通常用两种常用方法规划算法:流程图和伪代码。流程图使用符号和箭头直观地显示控制流程,而伪代码则用简单但有结构的英语描述步骤。
Both methods help you think logically and spot errors early. At KS3, you should be able to read a given flowchart or piece of pseudocode and predict its output, as well as create your own for simple tasks.
这两种方法都有助于你进行逻辑思考并及早发现错误。在 KS3 阶段,你应该能够阅读给定的流程图或伪代码并预测其输出,也能为简单任务创建自己的表达。
Why use them?
为什么使用它们?
- Flowcharts make the order of steps and decisions easy to see.
流程图让步骤和决策的顺序一目了然。 - Pseudocode bridges everyday language and programming code.
伪代码是日常语言和编程代码之间的桥梁。 - Both encourage decomposition—breaking a problem into smaller parts.
两者都鼓励分解——把问题拆分成更小的部分。
3. Flowchart Symbols | 流程图符号
Flowcharts use a standard set of shapes. You need to recognise these and draw them clearly in your work.
流程图使用一套标准的形状。你需要识别它们,并在作业中清晰地画出。
| Symbol | Name | Meaning |
|---|---|---|
| Oval | Terminator | Start or end of the algorithm |
| Rectangle | Process | An instruction or calculation |
| Parallelogram | Input / Output | Entering data or showing results |
| Diamond | Decision | A question with ‘Yes’ or ‘No’ branches |
| Arrow | Flow line | Shows direction of the next step |
(Note: In KS3 you will often draw rounded rectangles or ovals for start/end.)
(注意:在 KS3 中,你常会用圆角矩形或椭圆表示开始/结束。)
When you create a flowchart, always label arrows leaving a diamond with ‘Yes’ and ‘No’, and make sure the flow is logical. Practice by drawing a flowchart for a simple task like checking if a number is even.
创建流程图时,一定要在离开菱形的箭头上标上 ‘Yes’ 和 ‘No’,并确保流程合理。可以练习画一个简单任务的流程图,比如判断一个数是否为偶数。
4. Writing Pseudocode | 编写伪代码
Pseudocode is not an actual programming language; it is a way of writing down the logic of an algorithm using simple, readable statements. There are no strict rules, but at KS3 you should follow these conventions:
伪代码不是真正的编程语言;它是一种用简单可读的语句写下算法逻辑的方法。虽然规则不严格,但在 KS3 阶段你应该遵循以下惯例:
- Use words like INPUT, OUTPUT, IF…THEN…ELSE, WHILE…DO, FOR…TO…NEXT.
使用诸如 INPUT、OUTPUT、IF…THEN…ELSE、WHILE…DO、FOR…TO…NEXT 等词语。 - Indent blocks inside loops and conditions.
将循环和条件内的代码块缩进。 - Use arrows (←) for assignment, e.g. total ← 0.
使用箭头 (←) 表示赋值,例如 total ← 0。 - Keep it language-independent; avoid python-specific or javascript-specific syntax when practising for KS3 exams.
保持语言中立;在 KS3 考试练习中避免使用 Python 或 JavaScript 特有语法。
Example pseudocode to calculate the sum of the first 5 positive integers:
以下伪代码计算前五个正整数的和:
total ← 0
FOR count ← 1 TO 5 DO
total ← total + count
NEXT count
OUTPUT total
This shows how a loop can be used to repeat an action a fixed number of times.
这说明了如何使用循环将某个操作重复固定次数。
5. Sequence, Selection, Iteration | 顺序、选择、循环
Every algorithm is built from three fundamental control structures: sequence, selection, and iteration. Understanding these is a key KS3 requirement.
每个算法都由三种基本控制结构构成:顺序、选择和循环。理解这些是 KS3 的关键要求。
Sequence: Steps are carried out one after another in the order given. This is the simplest structure—like following a recipe.
顺序:步骤按给定的顺序一个接一个地执行。这是最简单的结构——就像遵循食谱一样。
Selection: A choice is made based on a condition. In flowcharts this is shown with a diamond. In pseudocode we use IF…THEN…ELSE. For example, ‘IF number MOD 2 = 0 THEN OUTPUT “even” ELSE OUTPUT “odd”‘.
选择:根据条件做出选择。在流程图中这用菱形表示。在伪代码中我们使用 IF…THEN…ELSE。例如,’IF number MOD 2 = 0 THEN OUTPUT “even” ELSE OUTPUT “odd”‘。
Iteration: Repeating a set of steps. There are two types:
循环:重复一组步骤。有两种类型:
- Count-controlled (definite) – uses FOR, repeating a set number of times.
计数控制(确定型)——使用 FOR,重复固定次数。 - Condition-controlled (indefinite) – uses WHILE, repeating as long as a condition is true.
条件控制(不确定型)——使用 WHILE,只要条件为真就重复。
At KS3, you will often be asked to identify these structures in a flowchart or pseudocode, and to write your own simple routines combining them.
在 KS3 中,你经常会被要求识别流程图或伪代码中的这些结构,并编写组合它们的简单程序。
6. Linear Search Algorithm | 线性搜索算法
A linear search (or sequential search) is the simplest way to find an item in a list. You check each element one by one until you find the target or reach the end.
线性搜索(或顺序搜索)是在列表中查找项的最简单方法。你逐个检查每个元素,直到找到目标或到达列表末尾。
Linear search algorithm steps:
线性搜索算法步骤:
- Start at the first element.
从第一个元素开始。 - Compare the current element with the target value.
将当前元素与目标值比较。 - If they match, output the position and stop.
如果匹配,输出位置并停止。 - If they do not match, move to the next element and repeat from step 2.
如果不匹配,移到下一个元素并重复步骤2。 - If the end of the list is reached without a match, output ‘not found’.
如果到达列表末尾仍未找到,输出 ‘not found’。
Example: Searching for the number 7 in the list [2, 5, 7, 1, 4] would check 2, then 5, then 7 and stop at position 3. This algorithm is simple but inefficient for large lists because in the worst case it checks every item.
例子:在列表 [2, 5, 7, 1, 4] 中搜索数字 7,会依次检查2、5,然后找到7并在位置3停止。这个算法简单,但对于大列表效率不高,因为最坏情况下要检查每一项。
7. Binary Search Algorithm | 二分搜索算法
A binary search is a much faster method, but it only works on a sorted list. It repeatedly divides the search space in half, eliminating large chunks at each step.
二分搜索是一种快得多的方法,但它只适用于已排序的列表。它反复将搜索区间对半分,每一步都排除大量元素。
Binary search algorithm steps for a list sorted in ascending order:
升序排列列表的二分搜索算法步骤:
- Let low = 1 and high = length of list.
设 low = 1,high = 列表长度。 - While low ≤ high, calculate mid = (low + high) DIV 2 (integer division).
当 low ≤ high 时,计算 mid = (low + high) DIV 2(整数除法)。 - Compare the middle element with the target:
将中间元素与目标比较: - If equal, output position and stop.
如果相等,输出位置并停止。 - If middle element is less than target, set low = mid + 1 (search right half).
如果中间元素小于目标,设 low = mid + 1(搜索右半部分)。 - If middle element is greater than target, set high = mid – 1 (search left half).
如果中间元素大于目标,设 high = mid – 1(搜索左半部分)。 - If low > high, output ‘not found’.
如果 low > high,输出 ‘not found’。
For example, searching for 18 in [2, 7, 10, 15, 18, 23, 30] first compares with 15 (mid), then discards the left half; next mid is 23, discarding right half; third mid is 18 – found in 3 steps, whereas linear search would take 5. Binary search is efficient, but the need for a sorted list is an important constraint.
例如,在 [2, 7, 10, 15, 18, 23, 30] 中搜索 18,首先与 15(中间)比较,舍弃左半部分;下一个中间是 23,舍弃右半部分;第三个中间是 18——3 步找到,而线性搜索需要 5 步。二分搜索效率高,但要求列表已排序是一个重要的限制。
8. Bubble Sort Algorithm | 冒泡排序算法
Sorting algorithms arrange data in order. Bubble sort is one of the simplest, often taught first because its logic mirrors how we might intuitively sort a small list of numbers.
排序算法将数据按顺序排列。冒泡排序是最简单的排序算法之一,通常最先教授,因为其逻辑类似于我们直观地对一小组数字进行排序。
Bubble sort repeatedly steps through the list, compares adjacent items, and swaps them if they are in the wrong order. The largest unsorted element ‘bubbles up’ to its correct position at the end of each pass.
冒泡排序反复遍历列表,比较相邻项,如果顺序错误就交换它们。每一轮遍历后,最大的未排序元素会 ‘冒泡’ 到它最终的正确位置。
Algorithm for ascending order:
升序排列算法:
- Set n = length of list.
设 n = 列表长度。 - For i from 1 to n-1:
For i 从 1 到 n-1: - For j from 1 to n-i:
For j 从 1 到 n-i: - If list[j] > list[j+1], swap them.
如果 list[j] > list[j+1],交换它们。 - After each outer loop, the last i elements are in their final places.
每次外层循环后,最后的 i 个元素已在最终位置。
Example: Sorting [5, 1, 4, 2]
例子:排序 [5, 1, 4, 2]
Pass 1: compare 5 and 1 → swap → [1,5,4,2]; compare 5 and 4 → swap → [1,4,5,2]; compare 5 and 2 → swap → [1,4,2,5]. End of pass 1, 5 is in place.
第一轮:比较 5 和 1 → 交换 → [1,5,4,2];比较 5 和 4 → 交换 → [1,4,5,2];比较 5 和 2 → 交换 → [1,4,2,5]。第一轮结束,5 就位。
Pass 2: [1,4,2,5] → compare 1,4 (no swap); compare 4,2 → swap → [1,2,4,5]. Pass 3: no swaps needed. Sorted in 2 passes.
第二轮:[1,4,2,5] → 比较 1,4(无交换);比较 4,2 → 交换 → [1,2,4,5]。第三轮:无需交换。两轮排序完成。
9. Insertion Sort Algorithm | 插入排序算法
Insertion sort builds the sorted list one element at a time, taking each unsorted item and inserting it into its correct position within the already sorted part. It is efficient for small datasets and is often used as part of more complex algorithms.
插入排序一次构建一个有序元素,依次取出未排序的元素,并将其插入到已排序部分的正确位置。它对于小数据集很高效,常被用作更复杂算法的一部分。
Algorithm for ascending order:
升序算法:
- Consider the first element sorted.
将第一个元素视为已排序。 - For each next element (key), compare it with elements in the sorted sublist from right to left.
对于接下来的每个元素(键),从右向左与已排序子列表中的元素比较。 - Shift larger elements one position to the right.
将较大的元素向右移动一个位置。 - Insert the key into its correct position.
将键插入其正确位置。
Example: Sorting [8, 3, 5, 2]
例子:排序 [8, 3, 5, 2]
Start: [8] sorted. Key = 3: compare with 8, shift 8 right → insert 3 → [3,8]. Key = 5: compare with 8, shift 8 right; compare with 3, no shift → insert 5 → [3,5,8]. Key = 2: shift 8,5,3 right → insert 2 → [2,3,5,8]. Sorted.
开始:[8] 已排序。键=3:与 8 比较,将 8 右移 → 插入 3 → [3,8]。键=5:与 8 比较,8 右移;与 3 比较,不移 → 插入 5 → [3,5,8]。键=2:将 8,5,3 右移 → 插入 2 → [2,3,5,8]。排序完成。
At KS3 you may be asked to trace these algorithms on a small list, showing each step clearly.
在 KS3 阶段,你可能需要对一个小列表跟踪这些算法,清楚地展示每一步。
10. Algorithms in Mathematics: Finding HCF using Euclid’s Algorithm | 数学中的算法:使用欧几里得算法求最大公约数
Algorithms are not only for computing; they are deeply rooted in mathematics. Euclid’s algorithm for finding the Highest Common Factor (HCF) of two numbers is over 2000 years old and still widely used.
算法不仅用于计算;它们深深植根于数学。用于求两个数的最大公约数(HCF)的欧几里得算法已有 2000 多年历史,至今仍广泛使用。
Euclid’s algorithm works by repeated subtraction or, more efficiently, by using division and remainders:
欧几里得算法通过重复减法,或者更高效地使用除法和余数来工作:
- Given two numbers a and b, where a > b.
给定两个数 a 和 b,其中 a > b。 - Replace a with b and b with a MOD b (the remainder when a is divided by b).
用 b 替换 a,用 a MOD b(a 除以 b 的余数)替换 b。 - Repeat until b becomes 0. The non-zero remainder just before this is the HCF.
重复直到 b 变成 0。在此之前的非零余数就是 HCF。
Example: Find HCF(252, 105)
例子:求 HCF(252, 105)
Step 1: 252 MOD 105 = 42 → now a=105, b=42
步骤1:252 MOD 105 = 42 → 现在 a=105, b=42
Step 2: 105 MOD 42 = 21 → a=42, b=21
步骤2:105 MOD 42 = 21 → a=42, b=21
Step 3: 42 MOD 21 = 0 → remainder 0, stop. HCF = 21.
步骤3:42 MOD 21 = 0 → 余数为 0,停止。HCF = 21。
This algorithm cleverly avoids listing all factors and is extremely efficient. Expressing it in pseudocode or a flowchart helps connect mathematical reasoning with algorithmic thinking.
这个算法巧妙地避免了列出所有因数,而且非常高效。用伪代码或流程图表达它,有助于将数学推理与算法思维连接起来。
11. Evaluating Algorithms: Efficiency and Correctness | 评估算法:效率与正确性
At KS3, you are expected not only to follow algorithms but also to evaluate them. Two key aspects are:
在 KS3,你不仅要能遵循算法,还要能评估它们。两个关键方面是:
Correctness: Does the algorithm always produce the right output for every valid input? Testing with different inputs, including edge cases (like an empty list or the target not being present), helps verify this.
正确性:算法是否对每个有效输入都产生正确的输出?用不同的输入进行测试,包括边界情况(如空列表或目标不存在),有助于验证这点。
Efficiency: How many steps does the algorithm take as the size of the input grows? We compare algorithms informally at KS3: for searching, linear search might need to check 1000 items in the worst case, while binary search on a sorted list of 1000 items needs only about 10 comparisons (because 210 ≈ 1000). For sorting, bubble sort and insertion sort both typically take many more comparisons than more advanced sorts, but they are fine for small sets.
效率:随着输入规模的增大,算法需要多少步?我们在 KS3 阶段非正式地比较算法:对于搜索,线性搜索在最坏情况下可能需要检查 1000 项,而二分搜索在包含 1000 项的排序列表中只需要大约 10 次比较(因为 210 ≈ 1000)。对于排序,冒泡排序和插入排序通常比更高级的排序算法需要更多的比较次数,但对于小数据集来说它们是可行的。
You might be asked questions like: ‘When would you choose a linear search over a binary search?’ The answer: when the list is unsorted, small, or only searched once, because the cost of sorting first might not be worth it.
你可能会被问到这样的问题:’什么时候你会选择线性搜索而不是二分搜索?’ 答案是:当列表未排序、很小或只搜索一次时,因为先排序的代价可能不值得。
12. Summary and Key Takeaways | 总结与要点
Algorithms form the foundation of computational thinking. In your KS3 maths curriculum, you have explored how to design and represent algorithms using flowcharts and pseudocode, and you have examined fundamental searching and sorting techniques. You also saw how classic mathematical methods like Euclid’s algorithm embody the same step-by-step logic.
算法是计算思维的基础。在 KS3 数学课程中,你已经探索了如何使用流程图和伪代码设计和表示算法,并研究了基本的搜索和排序技术。你也看到了像欧几里得算法这样的经典数学方法如何体现了同样的逐步逻辑。
Key points to remember:
需要记住的要点:
- Clearly define inputs, outputs and the sequence of steps.
明确定义输入、输出和步骤顺序。 - Use flowcharts for visual planning and pseudocode for structured English planning.
使用流程图进行视觉规划,用伪代码进行结构化英语规划。 - Know the differences between linear and binary search, and when each is suitable.
了解线性搜索和二分搜索的区别,以及各自的适用场景。 - Bubble sort and insertion sort are simple but less efficient for large datasets.
冒泡排序和插入排序简单,但对于大数据集效率较低。 - Always test your algorithm with normal and edge-case data.
始终用正常数据和边界数据测试你的算法。
Practise tracing algorithms on paper, writing pseudocode for maths problems, and converting simple tasks into flowcharts. These skills will not only help you in exams but also build logical reasoning useful in everyday life.
练习在纸上跟踪算法,为数学问题编写伪代码,以及将简单任务转化为流程图。这些技能不仅会在考试中帮助你,还能培养日常生活中非常有用的逻辑推理能力。
Published by TutorHao | Mathematics Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导