📚 PDF资源导航

IB WJEC Mathematics: Algorithms – Key Revision Points | IB WJEC 数学:算法 考点精讲

📚 IB WJEC Mathematics: Algorithms – Key Revision Points | IB WJEC 数学:算法 考点精讲

Mastering algorithms is a cornerstone of success in both IB and WJEC mathematics specifications, especially within the Decision Mathematics and Analysis & Approaches modules. This article unpacks the core concepts, common pitfalls, and exam-ready techniques for searching, sorting, and analysing algorithms – all supported by pseudocode, trace tables, and Big O notation. Use this revision guide to build confidence and tackle structured questions with precision.

掌握算法是 IB 和 WJEC 数学课程中取得高分的关键,尤其是在决策数学以及分析与方法模块中。本文拆解搜索、排序和算法分析的核心概念、常见易错点与应试技巧,并用伪代码、追踪表和大 O 符号加以阐述。利用这份备考指南,你可以建立信心,精准应对结构化考题。

1. Introduction to Algorithms and Pseudocode | 算法及伪代码简介

An algorithm is a finite sequence of well-defined, unambiguous instructions designed to solve a specific problem. It must possess five essential features: clearly specified inputs, defined outputs, definiteness (each step is unambiguous), finiteness (it terminates after a finite number of steps), and effectiveness (each step is basic enough to be carried out).

算法是为解决特定问题而设计的一个有限序列,其中每一步都是明确、无歧义的指令。它必须具有五个基本特征:明确规定的输入、定义的输出、确定性(每一步无歧义)、有限性(在有限步后终止)和有效性(每一步都足够基本,可以执行)。

Pseudocode is a simplified, informal way to describe an algorithm using structured English-like statements. Common constructs include DECLARE, INPUT, OUTPUT, IF…THEN…ELSE, FOR…TO…NEXT, WHILE…DO…ENDWHILE, and assignment with the arrow symbol ← or = . It allows examiners to assess logical thinking without strict syntax requirements, though you must maintain consistency.

伪代码是一种简化、非正式的描述算法方式,使用类似英语的结构化语句。常见构件包括 DECLAREINPUTOUTPUTIF…THEN…ELSEFOR…TO…NEXTWHILE…DO…ENDWHILE,以及用箭头符号 ← 或等号赋值。它让考官能够评估逻辑思维,而不需要严格的语法,但你仍需保持书写一致。


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

Flowcharts provide a visual representation of an algorithm’s control flow. The standard symbols are: a rounded rectangle or parallelogram for Input/Output, a rectangle for Process, a diamond for Decision (yes/no branches), and a terminator oval for Start/End. Arrows indicate the direction of flow.

流程图给出算法控制流的可视化表示。标准符号包括:输入/输出用圆角矩形或平行四边形,处理用矩形,判断用菱形(是/否分支),起止用椭圆形终结符。箭头指示流向。

When constructing a flowchart, ensure that every decision has two outgoing paths and that all loops have a clear exit condition. A classic example is checking whether a number N is even: read N, compute N MOD 2, and branch to output “Even” if the remainder is 0, otherwise output “Odd”.

构建流程图时,确保每个判断都有两条流出路径,所有循环都有明确的退出条件。一个经典例子是判断数字 N 是否为偶数:读取 N,计算 N MOD 2,如果余数为 0 则输出 “Even”,否则输出 “Odd”。


3. Linear Search: Step-by-Step | 线性搜索:逐步剖析

The linear search algorithm examines each element of a list in turn, starting from the first, until the target value is found or the end of the list is reached. It works on both sorted and unsorted data and is easy to implement, but inefficient for large data sets.

线性搜索算法从第一个元素开始依次检查列表中的每一项,直到找到目标值或到达列表末尾。它适用于有序和无序数据,实现简单,但对于大数据集效率很低。

Consider the list [4, 7, 2, 9, 5] and target 9. In pseudocode: WHILE position ≤ length of list AND item not found, compare list[position] with target; if equal, set found to true, else increment position. The search stops at index 4 (0-based). A trace table records the values of position, current element, and found status.

考虑列表 [4, 7, 2, 9, 5] 和目标值 9。伪代码如下:WHILE 位置 ≤ 列表长度且未找到,比较 list[position] 与目标值;若相等,置 found 为 true,否则递增 position。搜索在索引 4(基于 0)停止。追踪表记录 position、当前元素和 found 状态的值。


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

Binary search repeatedly divides a sorted list in half, discarding the half that cannot contain the target. It uses two pointers, low and high, and calculates mid = floor((low + high) / 2). If list[mid] equals the target, the search ends; if target is smaller, adjust high = mid − 1; if larger, adjust low = mid + 1.

二分查找反复将有序列表分成两半,丢弃不可能包含目标值的一半。它使用两个指针 low 和 high,计算 mid = ⌊(low + high)/2⌋。若 list[mid] 等于目标值,搜索结束;若目标值更小,则调整 high = mid − 1;若更大,则调整 low = mid + 1。

Apply it to the sorted list [2, 5, 7, 8, 12, 15] searching for 12. Initially low = 0, high = 5, mid = 2 (value 7). Since 12 > 7, low becomes 3. Next mid = 4 (value 12) → found. The algorithm requires only two comparisons, demonstrating O(log n) efficiency.

将它应用到有序列表 [2, 5, 7, 8, 12, 15] 搜索 12。初始 low = 0, high = 5, mid = 2(值为 7)。因为 12 > 7,low 变为 3。下一个 mid = 4(值为 12)→ 找到。算法只需两次比较,展示了 O(log n) 效率。


5. Bubble Sort: Simplest Sorting | 冒泡排序:最简单的排序

Bubble sort repeatedly passes through a list, comparing adjacent items and swapping them if they are in the wrong order. After each complete pass, the largest unsorted element “bubbles” to its final position. The algorithm stops when a pass occurs without any swaps.

冒泡排序反复遍历列表,比较相邻项,如果顺序错误就交换它们。每完成一趟完整遍历后,最大的未排序元素会 “冒泡” 到它的最终位置。当某一趟遍历未发生任何交换时,算法停止。

Given [5, 1, 4, 2, 8], the first pass compares 5 & 1 → swap → [1,5,4,2,8]; 5 & 4 → swap → [1,4,5,2,8]; 5 & 2 → swap → [1,4,2,5,8]; 5 & 8 → no swap. After pass 1, the list is [1,4,2,5,8] and 8 is in place. A trace table showing each step is essential for exams; remember to record the list state after each swap or at the end of a pass.

给定 [5, 1, 4, 2, 8],第一趟比较 5 和 1 → 交换 → [1,5,4,2,8];5 和 4 → 交换 → [1,4,5,2,8];5 和 2 → 交换 → [1,4,2,5,8];5 和 8 → 不交换。第一趟结束后,列表为 [1,4,2,5,8],8 归位。考试中必须展示追踪表;记得在每次交换后或每趟结束时记录列表状态。


6. Quick Sort: Divide and Conquer | 快速排序:分治之法

Quick sort selects a pivot element from the list and partitions the remaining elements into two sublists: those less than the pivot and those greater than the pivot. It then recursively applies the same process to the sublists. The pivot is then placed in its correct sorted position between the sublists.

快速排序从列表中选取一个枢轴元素,将剩余元素划分为两个子列表:小于枢轴的和大于枢轴的。然后对子列表递归地应用相同过程。枢轴随后被放置在两子列表之间的正确排序位置。

Using [8, 3, 5, 2, 9, 1, 4] with the first element as pivot (8): less-than sublist → [3,5,2,1,4]; greater-than sublist → [9]. Recursive sorting on [3,5,2,1,4] picks pivot 3, partitions to [2,1] and [5,4]. Continue until each sublist has length 0 or 1. The recombined list becomes [1,2,3,4,5,8,9]. Tracing quick sort requires showing the pivot choice and the state of sublists at each recursive step.

以 [8, 3, 5, 2, 9, 1, 4] 为例,选第一个元素为枢轴 (8):小于子列表 → [3,5,2,1,4];大于子列表 → [9]。对 [3,5,2,1,4] 递归排序,选枢轴 3,划分为 [2,1] 和 [5,4]。继续直到每个子列表长度为 0 或 1。重组后的列表为 [1,2,3,4,5,8,9]。追踪快速排序需展示每步递归的枢轴选择和子列表状态。


7. Tracing Algorithms and Dry Runs | 算法追踪与模拟运行

A dry run means manually stepping through an algorithm with sample data, recording variable values in a trace table. This technique is crucial for verifying correctness and is frequently tested in IB and WJEC exams. Construct columns for each variable and carefully update them line by line according to the pseudocode.

模拟运行指使用样本数据手动逐步执行算法,并在追踪表中记录变量值。这一技术对于验证正确性至关重要,在 IB 和 WJEC 考试中经常出现。为每个变量建立列,并根据伪代码逐行仔细更新。

For a binary search trace, a typical table includes low, high, mid, list[mid], and comparison result. If searching for 15 in [3, 8, 11, 15, 20], initial low=0, high=4, mid=2, list[2]=11, comparison: 15>11 → low=3; next row mid=3, list[3]=15 → found. Always tick off each pseudocode statement as you trace to avoid skipping steps.

对于二分查找追踪,典型表格包括 lowhighmidlist[mid] 和比较结果。在 [3, 8, 11, 15, 20] 中搜索 15,初始 low=0, high=4, mid=2, list[2]=11,比较:15>11 → low=3;下一行 mid=3, list[3]=15 → 找到。追踪时,务必逐条勾选伪代码语句,避免跳过步骤。


8. Efficiency and Big O Notation | 效率与大 O 符号

Big O notation describes the worst-case time complexity of an algorithm as a function of input size n. It ignores constant factors and lower-order terms, focusing on growth rate. For example, O(n²) means that if the input doubles, the execution time roughly quadruples.

大 O 符号描述算法最坏情况的时间复杂度,表示为输入规模 n 的函数。它忽略常数因子和低阶项,聚焦增长速率。例如 O(n²) 意味着如果输入加倍,执行时间大约变为四倍。

The following table summarises key complexities for algorithms in the syllabus:

下表总结了课程中关键算法的复杂度:

Algorithm Best Case Worst Case Notes
Linear Search O(1) O(n) Unsorted or sorted data
Binary Search O(1) O(log n) Requires sorted list
Bubble Sort O(n) O(n²) Adaptive with early exit
Quick Sort O(n log n) O(n²) Worst-case on already sorted data with poor pivot

Understanding these helps in algorithm selection. In practice, binary search is preferred for large sorted collections, and merge sort (if studied) offers guaranteed O(n log n) but requires extra memory.

理解这些有助于算法选择。在实践中,对于大型有序集合,二分查找更受青睐;若学习过归并排序,它保证 O(n log n),但需要额外内存。


9. Common Pitfalls in Exam Questions | 考试常见易错点

Many marks are lost due to minor errors that are entirely avoidable. First, forgetting to check that the list is sorted before applying binary search – the algorithm will produce incorrect results or infinite loops. Always verify the precondition.

许多失分都是由完全可以避免的小错误导致的。首先,在应用二分查找前忘记检查列表已排序——算法将产生错误结果或无限循环。务必验证前置条件。

Second, off-by-one errors in loop bounds. In pseudocode, whether arrays are indexed from 0 or 1 can affect the FOR loop termination. For bubble sort, the inner loop should go up to length − 1 − i (where i is the pass number). Using length − 1 alone causes unnecessary comparisons or missed swaps.

其次,循环边界的差一错误。在伪代码中,数组索引是从 0 还是 1 开始会影响 FOR 循环终止。对于冒泡排序,内循环应到 length − 1 − i(i 为趟号)。仅使用 length − 1 会导致不必要的比较或遗漏交换。

Third, when tracing quick sort, students sometimes forget to show the recursive call stack or incorrectly order the sublists during recombination. Also, failing to update all variables in a trace table for each statement leads to inconsistent snapshots. Practise dry runs under timed conditions to internalise the discipline.

第三,追踪快速排序时,学生有时忘记展示递归调用栈,或在重组时弄错子列表顺序。此外,执行每条语句时未更新追踪表中所有变量会导致快照不一致。在限时条件下练习模拟运行,将规范内化。


10. Applying Algorithms to Real-World Problems | 算法在现实问题中的应用

Algorithms are not just academic exercises; they underpin modern technology. Linear search is used in small databases or when scanning a linked list; binary search powers index lookups in databases and the binary search tree data structure employed by file systems.

算法不仅是学术练习,更是现代技术的基础。线性搜索用于小型数据库或扫描链表;二分查找支撑数据库中的索引查找和文件系统使用的二叉搜索树数据结构。

Bubble sort, despite its inefficiency, is sometimes useful for tiny data sets or educational purposes. Quick sort is the default sorting algorithm in many programming languages because of its average-case performance and in-place nature. Analysing these trade-offs — between time complexity, memory usage, and stability — is a key skill in algorithmic problem solving and appears in IB exploration tasks.

冒泡排序尽管效率低下,但在极小数据集或教学场景中有时有用。由于平均情况和就地排序的特性,快速排序在许多编程语言中是默认排序算法。分析这些取舍——时间复杂度、内存使用量与稳定性之间——是算法解决问题的关键技能,并出现在 IB 探究任务中。

Finally, understanding algorithmic thinking prepares you for deeper topics such as Dijkstra’s shortest path, Kruskal’s minimum spanning tree, and critical path analysis, which build directly on the fundamentals covered here.

最后,理解算法思维为你深入学习更深层的主题做好准备,如 Dijkstra 最短路径、Kruskal 最小生成树和关键路径分析,这些都直接建立在本节涵盖的基础之上。


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