Algorithms Key Points Revision | A-Level WJEC 数学:算法 考点精讲

📚 Algorithms Key Points Revision | A-Level WJEC 数学:算法 考点精讲

Algorithms form the backbone of computational thinking and problem-solving in mathematics. In the WJEC A-Level specification, you are expected not only to understand and apply standard algorithms but also to represent them using flowcharts and pseudocode, trace their execution, and compare their efficiency. This article covers every essential topic, from basic searching and sorting to the Euclidean algorithm, with clear step-by-step explanations and exam-focused tips.

算法是数学中计算思维和问题求解的基础。在 WJEC A-Level 考纲中,你不仅需要理解和应用标准算法,还要能够用流程图和伪代码表示它们、跟踪它们的执行过程并比较其效率。本文涵盖从基本搜索排序到欧几里得算法的所有核心主题,配以清晰的逐步讲解和应试技巧。


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

An algorithm is a finite sequence of well-defined, unambiguous instructions designed to solve a specific problem or perform a computation. It must be precise, terminate after a finite number of steps, and produce a correct output for any valid input. In WJEC examinations, you may be asked to describe the steps of an algorithm, identify its purpose, or correct a flawed version.

算法是一个有限的、定义明确且无歧义的指令序列,旨在解决特定问题或执行计算。它必须精确、在有限步后终止,并对任何有效输入产生正确输出。在 WJEC 考试中,你可能需要描述算法步骤、识别其目的或修正错误版本。

Algorithms are independent of programming languages; they focus on logic. Key properties include input, output, definiteness, finiteness, and effectiveness. When discussing algorithms, we often consider their time complexity, which measures how the number of operations grows with input size.

算法独立于编程语言,关注的是逻辑。关键属性包括输入、输出、确定性、有限性以及有效性。讨论算法时,我们常考虑其时间复杂度,衡量操作次数随输入规模的增长趋势。


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

Flowcharts provide a visual representation of an algorithm’s control flow using standard symbols. The key components are: oval shapes for start/end, rectangles for processes (e.g., assignment), diamonds for decisions (yes/no branches), and parallelograms for input/output. Arrows indicate the direction of flow, and all paths must eventually reach an End symbol.

流程图使用标准符号直观表示算法的控制流程。关键组件有:椭圆形表示开始/结束,矩形表示处理步骤(如赋值),菱形表示判断(是/否分支),平行四边形表示输入/输出。箭头指示流程方向,所有路径最终必须到达结束符号。

When drawing flowcharts for WJEC, label each decision outlet clearly with ‘Yes’ or ‘No’. Avoid crossing arrows; use connector dots only when necessary. Tracing a flowchart involves following the execution manually with a trace table, recording the values of variables at each step. This skill is frequently tested in the exam.

在为 WJEC 绘制流程图时,每个判断出口都要清晰标注“是”或“否”。避免箭头交叉;仅在必要时使用连接点。跟踪流程图需要用跟踪表手动跟随执行过程,记录每一步的变量值。这项技能在考试中常被考查。


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

Pseudocode is a structured, language-independent way to describe algorithms using plain English and mathematical notation. WJEC expects you to be familiar with common constructs: INPUT, OUTPUT, IF…THEN…ELSE, FOR…NEXT, WHILE…ENDWHILE, and assignments with the left-arrow symbol ‘←’ or ‘=’. Indentation is used to show block structure.

伪代码是一种结构化的、独立于语言的算法描述方式,使用简明英语和数学符号。WJEC 要求你熟悉常见结构:INPUT、OUTPUT、IF…THEN…ELSE、FOR…NEXT、WHILE…ENDWHILE,以及用左箭头 ‘←’ 或 ‘=’ 赋值。缩进用于展示代码块结构。

A typical pseudocode for summing numbers: Total ← 0, then FOR Count ← 1 TO n with Total ← Total + Count. Ensure your pseudocode is readable and unambiguous. You may be required to convert between flowcharts and pseudocode, so practice both representations.

一个典型的求和伪代码:Total ← 0,然后 FOR Count ← 1 TO n,执行 Total ← Total + Count。确保伪代码可读且无歧义。你可能需要实现流程图与伪代码间的互转,因此两种表示都要练习。


4. Basic Algorithms: Finding Maximum/Minimum | 基本算法:寻找最大/最小值

A fundamental algorithm scans a list of numbers to find the maximum value. The logic assumes the first item is the largest, then iteratively compares each subsequent item, updating the maximum when a larger value is found. This requires exactly n-1 comparisons for a list of n items, giving it an O(n) time complexity.

一个基础算法是扫描数字列表寻找最大值。逻辑是假设第一项最大,然后逐一比较后续各项,发现更大值时更新最大值。对于包含 n 项的列表,需要恰好 n-1 次比较,时间复杂度为 O(n)。

Pseudocode for maximum: Max ← A[1], then FOR i ← 2 TO n do IF A[i] > Max THEN Max ← A[i]. The minimum-finding version is symmetrical, using ‘<' instead. Tracing these algorithms helps you understand how variables change during execution; exam trace tables often include columns for i and the current Max or Min.

求最大值的伪代码:Max ← A[1],然后 FOR i ← 2 TO n 执行 IF A[i] > Max THEN Max ← A[i]。求最小值的版本是对称的,改用 ‘<'。跟踪这些算法有助于理解变量在执行中的变化;考试中的跟踪表常包含 i 和当前最大/最小值列。


5. Linear Search | 线性搜索

Linear search systematically checks every element of a list until the target is found or the list ends. It is simple and works on unordered data. The worst-case scenario requires checking all n items (found at the end or not present), yielding O(n) efficiency. In pseudocode, a flag ‘Found’ is often used to terminate early.

线性搜索系统地检查列表中的每个元素,直到找到目标或列表结束。它简单易行,适用于无序数据。最坏情形需要检查全部 n 项(目标在末尾或不存在),效率为 O(n)。伪代码中常用标志位 ‘Found’ 实现提前终止。

A traced example: searching for 7 in [2,5,8,7,1]. i=1, compare 2≠7; i=2, 5≠7; i=3, 8≠7; i=4, 7=7, set Found=TRUE and stop. If the target is absent, the algorithm examines every element. Linear search is contrasted with binary search to highlight efficiency trade-offs.

跟踪示例:在 [2,5,8,7,1] 中搜索 7。i=1,比较 2≠7;i=2,5≠7;i=3,8≠7;i=4,7=7,置 Found=TRUE 停止。若目标不存在,算法会检查每个元素。线性搜索常与二分搜索对比,以说明效率权衡。


6. Binary Search | 二分搜索

Binary search operates on a sorted list, repeatedly dividing the search interval in half. It compares the middle element with the target; if the target is smaller, the search continues in the left sublist, otherwise in the right. This logarithmic halving gives binary search an O(log n) time complexity, making it vastly more efficient for large data sets.

二分搜索应用于有序列表,反复将搜索区间折半。它比较中间元素与目标;若目标更小,搜索在左子区间继续,否则在右区间。这种对数式折半使二分搜索具有 O(log n) 时间复杂度,对于大数据集效率高出许多。

Key pseudocode steps: set Low ← 1, High ← n, Found ← FALSE. While Low ≤ High and not Found: Mid ← ⌊(Low+High)/2⌋; if A[Mid] = target, Found ← TRUE; else if target < A[Mid], High ← Mid−1; else Low ← Mid+1. The use of floor division is important for integer indices. WJEC exams often ask you to trace binary search with a table recording Low, High, Mid, and the comparison result.

关键伪代码步骤:置 Low ← 1,High ← n,Found ← FALSE。当 Low ≤ High 且未找到时:Mid ← ⌊(Low+High)/2⌋;若 A[Mid] = 目标,Found ← TRUE;否则若目标 < A[Mid],High ← Mid−1;否则 Low ← Mid+1。取整除法对整数索引很重要。WJEC 考试常要求你用表格记录 Low、High、Mid 和比较结果来跟踪二分搜索。


7. Bubble Sort | 冒泡排序

Bubble sort compares adjacent elements and swaps them if they are in the wrong order. This process is repeated until a full pass requires no swaps, indicating the list is sorted. It is an intuitive but inefficient O(n²) algorithm, suitable for small lists. In WJEC, you must know how to write its pseudocode, trace it, and state the number of comparisons/passes.

冒泡排序比较相邻元素,若顺序错误则交换它们。重复此过程,直到某一趟无需交换,表明列表已有序。它是一种直观但效率低下的 O(n²) 算法,适用于小型列表。在 WJEC 中,你必须会写其伪代码、进行跟踪,并说明比较/趟数。

Pseudocode: FOR i ← 1 TO n−1, FOR j ← 1 TO n−i, IF A[j] > A[j+1] THEN SWAP A[j] and A[j+1]. The inner loop reduces in length because after each pass, the largest element bubbles to its correct position. A possible optimisation uses a flag Swapped to halt early if no swaps occur. Trace tables typically capture the state of the list after each pass.

伪代码:FOR i ← 1 TO n−1,FOR j ← 1 TO n−i,IF A[j] > A[j+1] THEN SWAP A[j] 与 A[j+1]。内层循环长度递减,因为每趟之后最大元素冒泡到正确位置。一种优化是使用标志位 Swapped,若无交换则提前终止。跟踪表通常记录每趟后列表的状态。


8. Euclidean Algorithm | 欧几里得算法

The Euclidean algorithm efficiently computes the greatest common divisor (GCD) of two positive integers. It repeatedly applies the division algorithm: GCD(a, b) = GCD(b, a mod b), with the base case GCD(x, 0) = x. This algorithm appears frequently in WJEC number theory and algorithm questions, often requiring tracing with a table.

欧几里得算法高效地计算两个正整数的最大公因数 (GCD)。它反复应用带余除法:GCD(a, b) = GCD(b, a mod b),基本情况 GCD(x, 0) = x。该算法在 WJEC 数论和算法题中频繁出现,常需要用表格进行跟踪。

Pseudocode: WHILE b ≠ 0 Temp ← a mod b; a ← b; b ← Temp; ENDWHILE; OUTPUT a. For example, GCD(48, 18): 48 mod 18 = 12; then (18, 12) → 18 mod 12 = 6; (12, 6) → 12 mod 6 = 0; result is 6. The algorithm’s efficiency is O(log min(a,b)), which is excellent.

伪代码:WHILE b ≠ 0 Temp ← a mod b; a ← b; b ← Temp; ENDWHILE; OUTPUT a。例如 GCD(48, 18):48 mod 18 = 12;然后 (18, 12) → 18 mod 12 = 6;(12, 6) → 12 mod 6 = 0;结果为 6。该算法效率为 O(log min(a,b)),非常出色。


9. Algorithm Efficiency and Comparison | 算法效率与比较

WJEC expects you to compare algorithms based on operation counts, particularly for searching and sorting. The key measures are best-case, worst-case, and average-case performance. Linear search: best 1 comparison, worst n, average n/2. Binary search: worst-case about log₂ n comparisons. Bubble sort worst-case comparisons are (n−1)+(n−2)+…+1 = n(n−1)/2, which is O(n²).

WJEC 要求你根据操作次数对算法进行比较,尤其是搜索和排序算法。关键指标是最好情况、最坏情况和平均情况性能。线性搜索:最好 1 次比较,最坏 n 次,平均 n/2 次。二分搜索:最坏约 log₂ n 次比较。冒泡排序最坏比较次数为 (n−1)+(n−2)+…+1 = n(n−1)/2,即 O(n²)。

When evaluating efficiency, focus on how the number of key steps (comparisons, swaps) scales with input size n. Big-O notation is used informally; you might describe algorithms as ‘linear order’ or ‘quadratic order’. Recognising that binary search requires a sorted list while linear search does not is another important comparison point.

评估效率时,关注关键步骤(比较、交换)数量如何随输入规模 n 扩展。大 O 记法非正式使用;可描述算法为“线性阶”或“平方阶”。认识到二分搜索需要有序列表而线性搜索不需要,是另一个重要的比较点。


10. Tracing Algorithms and Trace Tables | 跟踪算法与跟踪表

Tracing is a fundamental exam skill; you are given an algorithm and must simulate its execution by hand. A trace table records the values of all variables and outputs at each step. The table is completed row by row, adding a new row whenever a variable changes. This method helps identify logic errors and ensures deep understanding.

跟踪是一项基本考试技能;你会拿到一个算法并必须手动模拟其执行。跟踪表记录每一步所有变量的值和输出。表格逐行填写,每次变量变化时新增一行。这种方法有助于识别逻辑错误并确保深入理解。

Example trace for a loop summing even numbers: start with Sum=0, i=2. Row 1: i=2, Sum=2; row 2: i=4, Sum=6; and so on until i>n. For binary search, columns: Low, High, Mid, A[Mid], Target, Output. Always initialise variables before entering loops, and be precise with index updates.

跟踪偶数求和的示例:起始 Sum=0,i=2。第 1 行:i=2,Sum=2;第 2 行:i=4,Sum=6;依此类推直到 i>n。对于二分搜索,列包括:Low、High、Mid、A[Mid]、目标、输出。进入循环前务必初始化变量,并精确更新索引。


11. Common Exam Topics and Tips | 常见考点与考试技巧

Exam questions often combine multiple aspects: you may be asked to identify the purpose of an algorithm, correct errors in a given flowchart, complete a partial pseudocode, or compare two algorithms. When comparing, explicitly mention data requirements (sorted vs. unsorted), the number of comparisons, and scalability.

考题常综合多个方面:你可能需要识别算法目的、修正给定流程图中的错误、补全不完整的伪代码,或比较两个算法。比较时,要明确提及数据要求(有序 vs. 无序)、比较次数和可扩展性。

Top tips: practice drawing flowcharts neatly, using a ruler and standard symbols. In pseudocode, consistency is key — use the same notation throughout. For trace tables, ensure all iterations are recorded; don’t skip updating loop counters. Check boundary conditions like empty lists or single-element cases, as these often reveal incorrect algorithms.

重要技巧:练习整洁地绘制流程图,使用直尺和标准符号。伪代码中,一致性至关重要——始终使用相同符号。对于跟踪表,确保记录所有迭代;不要跳过更新循环计数器。检查边界条件,如空列表或单元素情况,它们常暴露错误算法。

Additionally, familiarise yourself with other simple algorithms like digit extraction (using mod and integer division) or reversing a number. These are built upon basic control structures and are common in WJEC papers. Last but not least, when asked to write an algorithm, comment your pseudocode lightly to demonstrate your reasoning.

此外,要熟悉其他简单算法,如数字提取(使用取模和整除)或反转数字。它们建立在基本控制结构之上,常见于 WJEC 试卷。最后同样重要的是,当要求编写算法时,适当为伪代码添加注释以展示你的思路。

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