📚 PDF资源导航

Algorithms in CIE GCSE Mathematics | CIE GCSE 数学:算法考点精讲

📚 Algorithms in CIE GCSE Mathematics | CIE GCSE 数学:算法考点精讲

Algorithms are precise, step-by-step procedures designed to perform a specific task or solve a problem. In the CIE GCSE Mathematics syllabus, you need to interpret flowcharts, read and write pseudocode, trace algorithm execution, and understand classic algorithms for searching, sorting, and finding highest common factors. Mastering these topics strengthens your logical thinking and equips you to tackle structured exam questions confidently.

算法是旨在执行特定任务或解决问题的精确、逐步的过程。在 CIE GCSE 数学大纲中,你需要理解流程图、阅读和编写伪代码、追踪算法执行,并理解经典的搜索、排序和求最大公因数算法。掌握这些主题能加强你的逻辑思维,并让你自信地应对结构化的考试题目。


1. What is an Algorithm? | 什么是算法?

An algorithm is a finite sequence of well-defined instructions, typically used to solve a class of problems or to perform a computation. Algorithms are used in mathematics to carry out long division, find prime numbers, or compute the greatest common divisor in a systematic way.

算法是一个有限的、定义明确的指令序列,通常用于解决一类问题或执行计算。在数学中,算法被用来系统地执行长除法、寻找素数或计算最大公约数。

Every algorithm must have an input, a set of processing steps, and an output. The steps must be unambiguous and effective, meaning each step can be carried out in a finite amount of time. Algorithms can be represented in natural language, as a flowchart, or in pseudocode.

每个算法都必须有输入、一系列处理步骤和输出。这些步骤必须明确且有效,意味着每一步都可以在有限时间内完成。算法可以用自然语言、流程图或伪代码表示。

In the GCSE exam, you might be asked to identify the purpose of a given algorithm, trace its operation on specific inputs, or correct errors in a flowchart. You may also be asked to design a simple algorithm for a mathematical task, such as finding the mean of a list of numbers.

在 GCSE 考试中,你可能会被要求识别给定算法的目的、在特定输入上追踪其运行,或更正流程图中的错误。你还可能被要求为一个数学任务设计一个简单的算法,例如求一组数的平均值。


2. Representing Algorithms: Flowcharts | 算法的表示:流程图

Flowcharts use standard symbols to illustrate the sequence of steps in an algorithm. Recognising and interpreting these symbols is a fundamental exam skill. The table below summarises the most common flowchart symbols you need to know.

流程图使用标准符号来说明算法中的步骤顺序。识别和解释这些符号是一项基本的考试技能。下表总结了你需要知道的最常见的流程图符号。

Symbol Name Purpose
Oval Start/End Indicates the beginning or end of the algorithm.
Parallelogram Input/Output Shows data entry or display of results.
Rectangle Process Represents a calculation or assignment step.
Diamond Decision A condition check with ‘Yes’ and ‘No’ branches.
Arrow Flow line Shows the direction of logic flow.

An algorithm flowchart is read from top to bottom, following the arrows. Each step is performed in sequence unless a decision symbol redirects the flow. In the CIE GCSE exam, flowcharts are often used to represent iterative processes like finding the sum of numbers until a threshold is reached.

算法流程图按箭头从上到下阅读。除非决策符号重定向流程,否则将按顺序执行每个步骤。在 CIE GCSE 考试中,流程图通常用于表示迭代过程,例如求数字之和直到达到阈值。

For example, a flowchart to calculate the factorial of a positive integer N would include an oval Start, input N, initialise a result variable to 1, and then use a decision diamond to check whether a counter equals N. The process rectangle would multiply the result by the counter and increment it.

例如,计算正整数 N 的阶乘的流程图将包括一个开始椭圆、输入 N、将结果变量初始化为 1,然后使用决策菱形检查计数器是否等于 N。过程矩形会将结果乘以计数器并使其递增。


3. Representing Algorithms: Pseudocode | 算法的表示:伪代码

Pseudocode is a text-based way to describe algorithms using a simplified, language-independent syntax. CIE provides a standard pseudocode notation that includes constructs like INPUT, OUTPUT, IF … THEN … ELSE … ENDIF, FOR … TO … NEXT, WHILE … DO … ENDWHILE, and assignment with the arrow ←.

伪代码是一种基于文本的描述算法的方式,使用简化的、独立于语言的语法。CIE 提供了标准的伪代码表示法,包括 INPUT、OUTPUT、IF … THEN … ELSE … ENDIF、FOR … TO … NEXT、WHILE … DO … ENDWHILE 等结构,以及用箭头 ← 进行赋值。

You are expected to read and understand pseudocode, and occasionally write short segments. Variables are not declared with types; assignment is straightforward. The following example shows pseudocode to output the first 10 multiples of a number N:

你需要阅读和理解伪代码,并偶尔编写简短的片段。变量不需要声明类型;赋值是直接的。以下示例显示了输出数字 N 前 10 个倍数的伪代码:

INPUT N
FOR i ← 1 TO 10
OUTPUT i × N
NEXT i

When tracing pseudocode, you should keep a careful record of variable values at each step. Exam questions often give a pseudocode fragment and ask for the final value of a variable or the output produced. Practice with sorting and searching algorithms is particularly useful.

追踪伪代码时,你应该仔细记录每一步的变量值。考试题目通常会给出一个伪代码片段,并要求写出变量的最终值或生成的输出。练习排序和搜索算法尤为有用。


4. Basic Constructs: Sequence, Selection, Iteration | 基本结构:顺序、选择、迭代

All algorithms are built from three fundamental control structures: sequence, selection, and iteration. Understanding how they combine is essential for interpreting any flowchart or pseudocode.

所有算法都由三个基本控制结构构建:顺序、选择和迭代。理解它们如何组合对于解释任何流程图或伪代码至关重要。

Sequence means executing instructions one after another in order. No steps are skipped or repeated unless directed by other constructs. For example, computing the area of a circle involves inputting the radius, calculating π × radius², and outputting the result in strict sequence.

顺序意味着按顺序一条接一条地执行指令。除非其他结构指示,否则不会跳过或重复任何步骤。例如,计算圆的面积涉及输入半径、计算 π × 半径²,并严格按顺序输出结果。

Selection uses a condition to decide which path to take, typically with IF statements. In flowcharts, the diamond symbol checks a condition and branches to ‘Yes’ or ‘No’ paths. Pseudocode uses IF … THEN … ELSE … ENDIF. For instance, an algorithm might output ‘Pass’ if a mark ≥ 50, otherwise output ‘Fail’.

选择使用条件来决定走哪条路径,通常使用 IF 语句。在流程图中,菱形符号检查条件并分支到“是”或“否”路径。伪代码使用 IF … THEN … ELSE … ENDIF。例如,如果分数≥50,算法可能输出“Pass”,否则输出“Fail”。

Iteration repeats a block of code while a condition is met. You will encounter count-controlled loops (FOR … NEXT) and condition-controlled loops (WHILE … ENDWHILE). WHILE checks the condition before each iteration; the loop may not run at all if the condition is false initially. Iteration is used heavily in searching and sorting algorithms.

迭代在满足条件时重复一段代码。你会遇到计数控制循环(FOR … NEXT)和条件控制循环(WHILE … ENDWHILE)。WHILE 在每次迭代前检查条件;如果条件最初为假,循环可能根本不运行。迭代在搜索和排序算法中被大量使用。


5. Linear Search Algorithm | 线性搜索算法

The linear search algorithm looks for a target value by checking each item in a list one by one, from the first element to the last. It is simple and does not require the list to be sorted. This is often the first algorithm you will trace in a GCSE exam.

线性搜索算法通过逐个检查列表中的每一项来寻找目标值,从第一个元素到最后一个。它很简单,不要求列表有序。这通常是你在 GCSE 考试中追踪的第一个算法。

The steps in pseudocode for linear search of array A (size n) for target T are:

在数组 A(大小为 n)中线性搜索目标 T 的伪代码步骤如下:

i ← 0
WHILE i < n AND A[i] ≠ T
i ← i + 1
ENDWHILE
IF i < n THEN
OUTPUT “Found at index”, i
ELSE
OUTPUT “Not found”
ENDIF

The algorithm moves through the array until either the target is found or the end is reached. If no match exists, i equals n and the output is ‘Not found’. The worst-case number of comparisons for an unsuccessful search is n; the best case is 1 comparison.

该算法在数组中移动,直到找到目标或到达末尾。如果没有匹配项,i 等于 n,输出为“Not found”。不成功搜索的最坏情况比较次数为 n;最佳情况为 1 次比较。

In a flowchart, the linear search uses a decision diamond to compare the current array element with the target, and a loop back to the next element if they differ. You must be able to trace a complete search on a small list and state the output.

在流程图中,线性搜索使用决策菱形来比较当前数组元素与目标,如果不匹配则循环回到下一个元素。你必须能够在一个小列表上追踪完整的搜索,并说明输出。


6. Binary Search Algorithm | 二分查找算法

Binary search is a much more efficient algorithm for finding a target in a sorted list. It repeatedly divides the search interval in half, comparing the middle element with the target. Because the list must be sorted, it is not always applicable, but it dramatically reduces the number of comparisons.

二分查找是一种在有序列表中查找目标的高效得多的算法。它反复将搜索区间一分为二,将中间元素与目标进行比较。由于列表必须有序,它并不总是适用,但它大幅减少了比较次数。

The pseudocode for binary search on a sorted array A[0..n-1] for target T is:

在有序数组 A[0..n-1] 上二分查找目标 T 的伪代码如下:

low ← 0
high ← n – 1
found ← FALSE
WHILE low ≤ high AND found = FALSE
mid ← (low + high) DIV 2
IF A[mid] = T THEN
found ← TRUE
ELSE IF A[mid] < T THEN
low ← mid + 1
ELSE
high ← mid – 1
ENDIF
ENDWHILE
IF found = TRUE THEN
OUTPUT “Found at index”, mid
ELSE
OUTPUT “Not found”
ENDIF

After each comparison, either the target is found, or half the remaining elements are eliminated. The maximum number of comparisons for an array of size n is approximately log₂(n). For example, searching among 1024 elements requires at most 11 comparisons with binary search, compared to 1024 with linear search.

每次比较后,要么找到目标,要么消除剩余元素的一半。对于大小为 n 的数组,最大比较次数约为 log₂(n)。例如,在 1024 个元素中搜索,使用二分查找最多需要 11 次比较,而线性搜索需要 1024 次。

A flowchart for binary search includes a loop with several decision diamonds to update low and high. Exam trace questions often require you to show the values of low, high, mid and the decision at each iteration in a table.

二分查找的流程图包含一个带有多个决策菱形的循环,用于更新 low 和 high。考试追踪题通常要求你在表格中显示每次迭代的 low、high、mid 和决策的值。


7. Bubble Sort Algorithm | 冒泡排序算法

Bubble sort is a simple sorting algorithm that repeatedly steps through a list, compares adjacent elements, and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted. Although it is not efficient for large lists, it is a classic GCSE topic.

冒泡排序是一种简单的排序算法,它反复遍历列表,比较相邻元素,如果它们的顺序错误就交换它们。遍历列表的过程会重复进行,直到列表有序。虽然它对大列表效率不高,但它是 GCSE 的经典主题。

The algorithm in pseudocode for an array A of length n is:

长度为 n 的数组 A 的冒泡排序伪代码如下:

FOR i ← 1 TO n – 1
FOR j ← 0 TO n – 1 – i
IF A[j] > A[j + 1] THEN
temp ← A[j]
A[j] ← A[j + 1]
A[j + 1] ← temp
ENDIF
NEXT j
NEXT i

After the first pass, the largest element bubbles to the end. The outer loop ensures that after n-1 passes, the entire array is sorted. You can optimise the algorithm by stopping early if no swaps occur in a pass.

第一趟遍历后,最大的元素冒泡到末尾。外层循环确保经过 n-1 趟后,整个数组有序。你可以通过在某趟中没有发生交换时提前停止来优化算法。

When tracing a bubble sort, you need to carefully record the array state after each swap or after each pass. Exam questions may ask you to complete a partially given trace table or to determine how many comparisons and swaps are made for a specific list.

在追踪冒泡排序时,你需要仔细记录每次交换后或每趟后的数组状态。考试题目可能要求你完成部分给出的追踪表,或者确定特定列表进行了多少次比较和交换。


8. Euclidean Algorithm for HCF | 欧几里得算法求最大公约数

The Euclidean algorithm is an efficient method to compute the highest common factor (HCF), also known as the greatest common divisor (GCD), of two positive integers. It is based on the principle that the HCF of two numbers does not change if the larger number is replaced by its remainder when divided by the smaller number.

欧几里得算法是计算两个正整数的最大公因数(HCF,也称 GCD)的一种高效方法。它基于这样一个原理:如果用较大的数除以较小的数所得的余数替换较大的数,两个数的 HCF 不变。

The pseudocode using a WHILE loop is:

使用 WHILE 循环的伪代码如下:

INPUT a, b
WHILE b ≠ 0
r ← a MOD b
a ← b
b ← r
ENDWHILE
OUTPUT a

For example, to find the HCF of 48 and 18: a=48, b=18 → r=12, a=18, b=12 → r=6, a=12, b=6 → r=0, a=6, b=0. The output is 6. This algorithm always terminates because the new b (the remainder) is strictly smaller than the previous divisor.

例如,求 48 和 18 的 HCF:a=48, b=18 → r=12, a=18, b=12 → r=6, a=12, b=6 → r=0, a=6, b=0。输出为 6。该算法总能终止,因为新的 b(余数)严格小于之前的除数。

In an exam, you may be asked to trace the Euclidean algorithm for given numbers or to complete a flowchart that implements it. Sometimes you must use the algorithm to determine the HCF of three numbers by first finding the HCF of two, then finding the HCF of that result and the third number.

在考试中,你可能需要针对给定数字追踪欧几里得算法,或完成实现该算法的流程图。有时你必须使用该算法求三个数的 HCF,方法是先求两个数的 HCF,然后再求该结果与第三个数的 HCF。


9. Using HCF to Find LCM | 用最大公约数求最小公倍数

The least common multiple (LCM) of two positive integers can be found efficiently using the relationship LCM(a, b) = (a × b) ÷ HCF(a, b). This method avoids listing multiples and is directly testable in the context of algorithms.

两个正整数的最小公倍数(LCM)可以使用关系式 LCM(a, b) = (a × b) ÷ HCF(a, b) 高效地求出。此方法避免了列举倍数,并且可在算法相关题目中直接考查。

An algorithm to find both HCF and LCM would combine the Euclidean algorithm with a multiplication and division step. Pseudocode:

一个求 HCF 和 LCM 的算法会将欧几里得算法与乘法和除法步骤结合起来。伪代码:

INPUT a, b
product ← a × b
WHILE b ≠ 0
r ← a MOD b
a ← b
b ← r
ENDWHILE
HCF ← a
LCM ← product ÷ a
OUTPUT HCF, LCM

For instance, for 8 and 12, product = 96, HCF = 4, LCM = 96 ÷ 4 = 24. An exam question might present a flowchart with this logic and ask you to deduce the output for specific inputs, or to write the corresponding pseudocode.

例如,对于 8 和 12,乘积 = 96,HCF = 4,LCM = 96 ÷ 4 = 24。考试题目可能呈现带有此逻辑的流程图,并要求你推断特定输入的输出,或写出相应的伪代码。


10. Tracing Algorithms by Dry Run | 通过干运行追踪算法

A dry run is the manual simulation of an algorithm’s execution on paper, carefully updating variable values at each step. It is a vital skill for debugging and for understanding how an algorithm works. CIE GCSE exam questions frequently require you to complete a trace table.

干运行是在纸上手动模拟算法的执行,在每个步骤仔细更新变量值。对于调试和理解算法如何工作,这是一项至关重要的技能。CIE GCSE 考试题目经常要求你完成追踪表。

A trace table typically has a column for each variable and a row for each step or iteration. You must systematically step through the pseudocode or flowchart, updating entries as assignments occur. When a value changes, you write the new value in the next row. Condition evaluation drives the flow.

追踪表通常为每个变量设置一列,并为每个步骤或迭代设置一行。你必须系统地逐步执行伪代码或流程图,在赋值发生时更新条目。当值改变时,你在下一行写入新值。条件评估驱动流程。

Example: trace the algorithm sum ← 0; FOR i ← 1 TO 4; sum ← sum + i; NEXT i; OUTPUT sum. The trace table would record i = 1, sum = 1; i = 2, sum = 3; i = 3, sum = 6; i = 4, sum = 10; output 10.

示例:追踪算法 sum ← 0; FOR i ← 1 TO 4; sum ← sum + i; NEXT i; OUTPUT sum。追踪表将记录 i = 1, sum = 1; i = 2, sum = 3; i = 3, sum = 6; i = 4, sum = 10; 输出 10。

When tracing sorting or searching algorithms, you may need to show the state of an array as well. Be meticulous with indices and ensure you follow the algorithm exactly, even if you notice an optimization; the dry run must reflect the given pseudocode literally.

在追踪排序或搜索算法时,你可能还需要显示数组的状态。要仔细处理索引,并确保完全遵循算法,即使你注意到可以优化;干运行必须严格反映给定的伪代码。


11. Exam Tips and Common Mistakes | 考试技巧与常见错误

Success in algorithm questions comes from careful practice and attention to detail. Here are key tips for the CIE GCSE Mathematics exam:

算法题目的成功来自于仔细的练习和对细节的关注。以下是 CIE GCSE 数学考试的关键技巧:

  • Always read the question to determine whether you need to interpret, trace, complete, or write an algorithm. Underline command words like ‘Trace’, ‘State’, ‘Complete’, ‘Write pseudocode’.

    始终阅读题目,确定是需要解释、追踪、完成还是编写算法。在命令词下划线,如“Trace”、“State”、“Complete”、“Write pseudocode”。

  • In flowcharts, follow arrows precisely and never skip a step. Remember that a decision diamond has exactly one entry and two exits (Yes/No).

    在流程图中,精确遵循箭头,绝不跳过任何步骤。记住决策菱形只有一个入口和两个出口(是/否)。

  • When writing pseudocode, use the standard CIE conventions: ← for assignment, = for comparison, DIV for integer division, MOD for remainder. Be consistent with indentation.

    编写伪代码时,使用标准 CIE 约定:← 表示赋值,= 表示比较,DIV 表示整除,MOD 表示余数。保持缩进一致。

  • In trace tables, initialise variables before entering loops. Never leave a cell blank; carry forward the previous value if unchanged.

    在追踪表中,进入循环前初始化变量。不要让单元格留空;如果未更改,则沿用前一个值。

  • A common mistake in binary search is forgetting to set found to FALSE or miscalculating mid as (low + high)/2 without integer division. Another pitfall in bubble sort is using the wrong loop bounds, causing out-of-range errors.

    二分查找中一个常见错误是忘记将 found 设为 FALSE,或者错误地将 mid 计算为 (low + high)/2 而不进行整除。冒泡排序中的另一个陷阱是使用错误的循环边界,导致越界错误。

  • Show all working clearly, especially re-written array states in sorting traces. Marks are often awarded for intermediate steps.

    清晰地展示所有解题过程,特别是在排序追踪中重新写入的数组状态。中间步骤通常都有分数。


12. Worked Example: Tracing a Bubble Sort | 典型例题:追踪冒泡排序

Let’s work through a typical exam question. Consider the array A = [4, 2, 5, 1, 3]. Use the bubble sort pseudocode from Section 7 to trace the algorithm and show the array after each complete pass. State the number of passes and the total number of swaps.

让我们完成一个典型的考试题目。考虑数组 A = [4, 2, 5, 1, 3]。使用第 7 节中的冒泡排序伪代码来追踪该算法,并显示每完整一趟后的数组。说明趟数和交换总数。

We start with the original array. The outer loop i runs from 1 to 4 (n-1). For each pass, we compare adjacent elements up to n-1-i and swap if out of order.

我们从原始数组开始。外层循环 i 从 1 到 4(n-1)。每趟中,我们比较直到 n-1-i 的相邻元素,如果顺序错误则交换。

Pass 1 (i=1): compare 4 and 2 → swap → [2,4,5,1,3]; compare 4 and 5 → no swap; compare 5 and 1 → swap → [2,4,1,5,3]; compare 5 and 3 → swap → [2,4,1,3,5]. End of pass. 3 swaps.

第 1 趟 (i=1): 比较 4 和 2 → 交换 → [2,4,5,1,3]; 比较 4 和 5 → 不交换; 比较 5 和 1 → 交换 → [2,4,1,5,3]; 比较 5 和 3 → 交换 → [2,4,1,3,5]。趟结束。3 次交换。

Pass 2 (i=2): array = [2,4,1,3,5]; compare 2 and 4 → no swap; compare 4 and 1 → swap → [2,1,4,3,5]; compare 4 and 3 → swap → [2,1,3,4,5]. 2 swaps.

第 2 趟 (i=2): 数组 = [2,4,1,3,5]; 比较 2 和 4 → 不交换; 比较 4 和 1 → 交换 → [2,1,4,3,5]; 比较 4 和 3 → 交换 → [2,1,3,4,5]。2 次交换。

Pass 3 (i=3): [2,1,3,4,5]; compare 2 and 1 → swap → [1,2,3,4,5]; compare 2 and 3 → no swap. 1 swap.

第 3 趟 (i=3): [2,1,3,4,5]; 比较 2 和 1 → 交换 → [1,2,3,4,5]; 比较 2 和 3 → 不交换。1 次交换。

Pass 4 (i=4): [1,2,3,4,5]; compare 1 and 2 → no swap. 0 swaps. The array is now sorted. Total passes = 4, total swaps = 6.

第 4 趟 (i=4): [1,2,3,4,5]; 比较 1 和 2 → 不交换。0 次交换。数组已排序。总趟数 = 4,总交换次数 = 6。

If we had implemented an optimisation to detect when no swaps occur, the algorithm could stop after pass 4 or even earlier with a flag. In an exam, follow the given pseudocode precisely; if it lacks an early exit, you must complete all n-1 passes unless the question specifies otherwise.

如果我们实现了一个优化来检测何时没有交换发生,算法可以在第 4 趟后甚至更早停止。在考试中,严格遵循给定的伪代码;如果缺少提前退出,你必须完成所有 n-1 趟,除非题目另有说明。

This example illustrates the importance of methodical tracing. Practice with different arrays of length 4 to 6 to become fluent in both bubble sort and the other algorithms discussed. Mastering algorithm tracing will significantly boost your confidence and marks in the GCSE examination.

这个例子说明了有条理地追踪的重要性。使用长度为 4 到 6 的不同数组进行练习,以熟练掌握冒泡排序和所讨论的其他算法。掌握算法追踪将显著增强你在 GCSE 考试中的信心和成绩。

Published by TutorHao | Mathematics Revision Series | aleveler.com

更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading