📚 Algorithm Essentials for IGCSE WJEC Computer Science | IGCSE WJEC 计算机:算法考点精讲
Algorithms are the beating heart of computer science. They define the step-by-step logic that transforms input into output, power everything from search engines to smartphone apps, and form the core of the WJEC IGCSE Computer Science specification. Mastering algorithm fundamentals – including pseudocode, sorting, searching, and efficiency analysis – will not only secure high marks in the exam but also build robust problem-solving skills for your future studies. This revision guide unpacks every key concept with clear English–Chinese explanations, ensuring you are fully prepared for any algorithm‑based question.
算法是计算机科学跳动的心脏。它们定义了将输入转化为输出的逐步逻辑,为从搜索引擎到智能手机应用的一切提供动力,也是 WJEC IGCSE 计算机科学大纲的核心。掌握算法基础——包括伪代码、排序、搜索和效率分析——不仅能在考试中拿下高分,还能为你未来的学习建构扎实的问题解决能力。这份复习指南用清晰的中英双语讲解拆解每个关键概念,确保你对任何基于算法的考题都准备充分。
1. What is an Algorithm? | 什么是算法?
An algorithm is a precise, finite sequence of well‑defined steps designed to solve a specific problem or perform a computation. It must be unambiguous – at each step, the next action is clearly determined – and it must always terminate after a limited number of operations. In everyday life, a recipe for baking a cake or a set of assembly instructions for flat‑pack furniture are analogies for algorithms: you follow a predetermined order of actions to achieve a desired result.
算法是一个精确、有限的步骤序列,由定义清晰的指令组成,旨在解决特定问题或完成某种计算。它必须无歧义——每一步的后续行动都明确确定——并且必须在有限次操作后终止。在日常生活中,烘焙蛋糕的食谱或组装平板家具的说明书就是算法的类比:你按照预先确定的操作顺序来得到想要的结果。
2. Characteristics of Algorithms | 算法的特征
For a process to qualify as an algorithm, it must exhibit five essential characteristics. First, Finiteness: the algorithm must always finish after a finite number of steps. Second, Definiteness: each step must be precisely stated; there can be no ambiguity in the meaning of an instruction. Third, Input: it may have zero or more inputs, taken from a specified set of objects. Fourth, Output: it must produce at least one output as a result. Fifth, Effectiveness: every operation must be sufficiently basic that it can, in principle, be carried out using pen and paper in a finite amount of time.
一个过程要成为算法,必须具备五个基本特征。第一,有穷性:算法必须在有限步之后终止。第二,确定性:每一步都必须精确定义,指令的意义不能存在歧义。第三,输入:可以有零个或多个取自特定对象集合的输入。第四,输出:必须至少产生一个结果作为输出。第五,可行性:每个操作都必须足够基本,原则上可以用纸笔在有限时间内完成。
3. Pseudocode and Flowcharts | 伪代码与流程图
WJEC expects candidates to express algorithms using both pseudocode and flowcharts. Pseudocode is a simplified, structured version of English (or any language) that resembles programming code but omits strict syntax rules. It uses keywords such as INPUT, OUTPUT, IF … THEN … ELSE … ENDIF, and WHILE … ENDWHILE. Flowcharts, on the other hand, are visual diagrams in which different shapes represent different types of operation: ovals for start/stop, parallelograms for input/output, rectangles for processes, and diamonds for decisions.
WJEC 要求考生能够用伪代码和流程图两种方式表达算法。伪代码是一种简化的结构化英语(或任何语言),外观接近编程代码但省略了严格的语法规则。它使用诸如 INPUT、OUTPUT、IF … THEN … ELSE … ENDIF 以及 WHILE … ENDWHILE 等关键词。流程图则是可视化图表,其中不同形状代表不同类型的操作:椭圆形表示开始/结束,平行四边形表示输入/输出,矩形表示处理步骤,菱形表示判断。
When drawing flowcharts, arrows must indicate the flow of control; a condition in a diamond has one arrow for ‘True’ and another for ‘False’. A correct flowchart always has a single start symbol and at least one stop symbol. In the exam, you may be asked to convert a description of a problem into a flowchart or pseudocode, or to interpret a given algorithm and trace its execution.
绘制流程图时,箭头必须表示控制流程;菱形中的判断条件要有两个出口,分别为“真”和“假”。正确的流程图总是有一个开始符号和至少一个停止符号。考试中,你可能需要将问题描述转化为流程图或伪代码,或者解读给定的算法并跟踪其执行过程。
4. Sequence, Selection and Iteration | 顺序、选择和迭代
All algorithms are built from just three fundamental constructs. Sequence means executing instructions one after another in the order they appear. Selection allows the algorithm to make decisions and choose between alternative paths using constructs such as IF … THEN … ELSE. Iteration (or repetition) enables a block of code to be executed repeatedly; WJEC recognises two types: count‑controlled loops (e.g., FOR i ← 1 TO 10) and condition‑controlled loops (e.g., WHILE x > 0 or REPEAT … UNTIL …).
所有算法都只由三种基本结构构建而成。顺序意味着按出现的先后顺序一条接一条地执行指令。选择让算法能够使用如 IF … THEN … ELSE 这样的结构做出决策并在不同路径间选择。迭代(或称重复)使一块代码能够被反复执行;WJEC 认可两种类型:计数控制循环(如 FOR i ← 1 TO 10)和条件控制循环(如 WHILE x > 0 或 REPEAT … UNTIL …)。
It is essential to use these constructs correctly in pseudocode. Indentation should clearly show which statements belong inside a loop or an IF block. Missing an ENDIF or an ENDWHILE will lose marks, because the examiner will conclude the structure is ambiguous.
在伪代码中正确使用这些结构至关重要。缩进应清楚标明哪些语句属于循环或 IF 块内部。遗漏 ENDIF 或 ENDWHILE 会失分,因为考官会认为结构存在歧义。
5. Linear Search | 线性搜索
A linear search inspects each element of a list in turn until the target value is found or the end of the list is reached. It does not require the data to be sorted, which makes it useful for small or unsorted datasets. In pseudocode:
线性搜索依次检查列表中的每一个元素,直到找到目标值或到达列表末尾。它不要求数据已排序,因此在小型或未排序的数据集中很实用。伪代码如下:
FOR index ← 0 TO length‑1
IF list[index] = target THEN
OUTPUT index
STOP
ENDIF
ENDFOR
OUTPUT “Not found”
The worst‑case scenario occurs when the target is the last element or not present at all; the algorithm must examine every item. Its time complexity is O(n). In the exam, you may be asked to perform a dry run using a trace table, counting the number of comparisons made for a given dataset.
最坏情况发生在目标值是最后一个元素或者根本不在列表中时,算法必须检查每一项。其时间复杂度为 O(n)。在考试中,你可能会被要求用跟踪表执行一次演算,统计给定数据集所做的比较次数。
6. Binary Search | 二分搜索
Binary search operates on a sorted list by repeatedly dividing the search interval in half. It compares the target value to the middle element of the current interval. If they match, the search ends successfully. If the target is smaller, the search continues on the left half; if larger, on the right half. This process repeats until the target is found or the interval is empty.
二分搜索在已排序的列表上工作,通过反复将搜索区间减半来查找。它将目标值与当前区间的中间元素比较。如果相等,搜索成功结束。如果目标值更小,则继续在左半部分搜索;如果更大,则在右半部分继续。重复这一过程,直到找到目标或区间为空。
low ← 0
high ← length‑1
WHILE low ≤ high
mid ← (low + high) DIV 2
IF list[mid] = target THEN
OUTPUT mid
STOP
ELSE IF list[mid] < target THEN
low ← mid + 1
ELSE
high ← mid – 1
ENDIF
ENDWHILE
OUTPUT “Not found”
Binary search is far more efficient than linear search on large datasets; its worst‑case time complexity is O(log n). However, it demands that the data be sorted first, which may add an overhead. WJEC questions often ask you to compare the two search methods in terms of the number of steps required for a given list size.
二分搜索在大数据集上远比线性搜索高效;最坏情况时间复杂度为 O(log n)。但它要求数据事先排序,这可能会增加额外开销。WJEC 常见题目是让你根据给定的列表大小,比较两种搜索方法所需的步骤数。
7. Bubble Sort | 冒泡排序
Bubble sort works by repeatedly stepping through a list, comparing adjacent elements and swapping them if they are in the wrong order. After each full pass, the next largest unsorted element “bubbles up” to its correct position at the end of the list. This process repeats until no swaps are needed in a complete pass, indicating the list is sorted.
冒泡排序通过反复遍历列表,比较相邻元素并在顺序错误时交换它们来工作。每完成一次完整遍历,下一个最大的未排序元素就会“冒泡”到列表末尾的正确位置。重复这一过程,直到某次遍历中没有任何交换发生,表明列表已经有序。
The algorithm can be made more efficient by reducing the range of each pass, because the last i elements are already in place after i passes. Pseudocode often uses a Boolean variable swapped to detect early completion, thereby avoiding unnecessary passes when the list becomes sorted ahead of time.
可以通过缩减每次遍历的范围来提高效率,因为经过 i 次遍历后,末尾的 i 个元素已经就位。伪代码常使用一个布尔变量 swapped 来检测提前完成,从而在列表提前有序时避免不必要的遍历。
Bubble sort’s time complexity is O(n²) in the worst and average cases. Despite its simplicity, it is inefficient for large datasets. The WJEC specification often examines the number of comparisons and swaps performed for a specific array of numbers, so be ready to calculate these in a trace table.
冒泡排序在最坏和平均情况下的时间复杂度均为 O(n²)。尽管它很简单,但对大数据集效率低下。WJEC 大纲常考查针对特定数字数组所执行的比较和交换次数,因此要准备好用跟踪表算出这些数据。
8. Merge Sort | 归并排序
Merge sort is a divide‑and‑conquer algorithm that recursively splits a list into smaller sub‑lists until each sub‑list contains a single element (which is trivially sorted). It then repeatedly merges adjacent sub‑lists, comparing the smallest remaining elements, to produce new sorted sub‑lists until one fully sorted list remains.
归并排序是一种分治算法,它递归地将列表拆分为越来越小的子列表,直到每个子列表只包含一个元素(此时自然有序)。然后,它反复合并相邻的子列表,比较各子列表中最小的剩余元素,生成新的有序子列表,直到最后只剩下一个完全排序的列表。
The key advantage of merge sort is its consistent O(n log n) time complexity in all cases – best, average, and worst. This makes it highly efficient for sorting large datasets. However, it requires additional memory space proportional to the size of the list, as the merging process uses temporary arrays.
归并排序的主要优点是在所有情况下(最好、平均、最坏)都保持 O(n log n) 的时间复杂度,这对于排序大数据集非常高效。但它在合并过程中需要使用临时数组,因此需要与列表大小成正比的额外内存空间。
In WJEC exams, merge sort questions may ask you to illustrate each split and merge step for a small array of numbers, or to compare its performance with bubble sort. Understanding the recursive nature and the merging logic is essential.
在 WJEC 考试中,归并排序的题目可能要求你针对小型数字数组图解每一步拆分和合并的过程,或者比较它与冒泡排序的性能。理解其递归本质和合并逻辑至关重要。
9. Algorithm Efficiency and Big-O | 算法效率与大O表示法
Algorithm efficiency is measured by how the time taken (or memory used) grows as the size of the input, n, increases. Big‑O notation describes an upper bound on this growth, helping us compare algorithms independently of hardware speed. The most common time complexities you need to know for WJEC are:
算法效率通过运行时间(或内存使用)随输入规模 n 增长的速度来衡量。大O表示法描述这种增长的上界,使我们能撇开硬件速度来比较算法。WJEC 要求掌握的最常见时间复杂度如下:
| Big‑O / 大O | Name / 名称 | Example / 示例 |
|---|---|---|
| O(1) | Constant / 常数 | Accessing an array element / 访问数组元素 |
| O(log n) | Logarithmic / 对数 | Binary search / 二分搜索 |
| O(n) | Linear / 线性 | Linear search / 线性搜索 |
| O(n²) | Quadratic / 平方 | Bubble sort / 冒泡排序 |
| O(n log n) | Log‑linear / 线性对数 | Merge sort / 归并排序 |
When you write an algorithm, you should be able to identify nested loops, because a loop inside another loop typically multiplies the number of operations and leads to O(n²) complexity. The WJEC exam might ask you to deduce the Big‑O of a given pseudocode fragment or to explain why binary search is more efficient than linear search for large n.
当你编写算法时,应能识别嵌套循环,因为一个循环内部嵌套另一个循环通常会使操作次数倍增,导致 O(n²) 的复杂度。WJEC 考试可能会要求你推断给定伪代码片段的大O,或者解释为什么对于较大的 n,二分搜索比线性搜索更高效。
10. Trace Tables | 跟踪表
A trace table is an essential tool for manually stepping through an algorithm, recording the values of variables as each instruction executes. It helps you verify correctness, understand how loops and conditions behave, and debug logic errors. WJEC exams regularly feature tasks where you must complete a trace table for a given pseudocode and set of inputs, so practise constructing them carefully.
跟踪表是手动逐步执行算法、记录每条指令执行后变量值的重要工具。它能帮助你验证算法的正确性,理解循环和条件的行为,并调试逻辑错误。WJEC 考试经常出现必须为给定伪代码和输入数据补全跟踪表的题目,因此要认真练习构建跟踪表。
When building a trace table, list all variables and outputs in the top row. Work through the algorithm line by line, updating the table whenever a variable changes or an output is produced. Pay particular attention to loop boundaries and condition evaluations; a common mistake is to stop tracing too early or to forget to update the loop counter.
在构建跟踪表时,在首行列明所有变量和输出。逐行执行算法,每当变量值改变或产生输出时就更新表格。特别要注意循环边界和条件判断;一个常见错误是过早停止执行,或忘记更新循环计数器。
11. Common Mistakes and Exam Tips | 常见错误与应试技巧
Mistake 1: Uninitialised variables. Always set a starting value for counters, totals, or flags before using them in an expression or loop condition.
错误 1:变量未初始化。 在表达式或循环条件中使用计数器、总和或标志变量之前,务必设置初始值。
Mistake 2: Infinite loops. In a WHILE loop, ensure the condition eventually becomes false by updating the relevant variable inside the loop. Forgetting to increment a counter or to change the sentinel value will cause the loop to run forever (and lose marks).
错误 2:无限循环。 在 WHILE 循环中,要确保通过更新循环体内相关变量使条件最终变为假。忘记递增计数器或改变哨兵值将导致循环永远运行(并且失分)。
Mistake 3: Incorrect indentation. Pseudocode is assessed partly on clarity; indentation shows which statements are inside a selection or iteration block. Without it, the structure becomes ambiguous.
错误 3:缩进不正确。 伪代码评分部分依赖清晰度;缩进能表明哪些语句属于选择或迭代块。缺少缩进会使结构产生歧义。
Mistake 4: Confusing assignment and comparison. Use ← for assignment (e.g., count ← 0) and = or ≠ for comparison. Using `=` for both can confuse the logic.
错误 4:混淆赋值与比较。 使用 ← 表示赋值(如 count ← 0),用 = 或 ≠ 表示比较。都用 `=` 会混淆逻辑。
Mistake 5: Rushing to code without planning. When asked to design an algorithm, first jot down the key steps in a flowchart or rough pseudocode before committing to a final answer. A clear plan prevents structural errors.
错误 5:不规划就匆忙写代码。 当被要求设计算法时,先草拟关键步骤,用流程图或粗略伪代码理清思路,再写出最终答案。清晰的规划能避免结构错误。
12. How Algorithms Are Assessed in the WJEC IGCSE | WJEC IGCSE 中算法的评估方式
The WJEC IGCSE Computer Science exam typically tests algorithms through a mixture of short‑answer questions and extended design tasks. You might be asked to:
WJEC IGCSE 计算机科学考试通常通过简答题和扩展设计题组合的方式考查算法。你可能会被要求:
- Complete a trace table for a given algorithm and data set. / 为给定算法和数据集补全跟踪表。
- Identify the purpose of an algorithm from its pseudocode. / 根据伪代码识别算法的目的。
- Write pseudocode to solve a simple problem such as finding the largest number in a list or counting occurrences of a character. / 编写伪代码来解决简单问题,例如找出列表中最大的数或统计某字符出现的次数。
- Compare search or sort algorithms in terms of efficiency, number of comparisons, or suitability for different scenarios. / 比较搜索或排序算法的效率、比较次数或在不同场景下的适用性。
- Draw a flowchart from a written description or pseudocode. / 根据文字描述或伪代码绘制流程图。
To prepare, practise writing algorithms by hand, paying close attention to the strict pseudocode syntax expected by WJEC. Time yourself when drawing flowcharts, because neatness and correct use of symbols matter. Review mark schemes to understand exactly where marks are awarded – often for correct initialisation, proper loop termination, and handling of edge cases such as an empty list.
备考时,多练习手写算法,严格遵守 WJEC 期望的伪代码语法。绘制流程图时计时练习,因为整洁度和符号的正确使用很重要。查阅评分方案,准确理解得分点在哪里——通常在于正确初始化、恰当结束循环,以及处理诸如空列表等边界情况。
Published by TutorHao | IGCSE Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导