📚 GCSE Edexcel Computer Science: Algorithms Key Points | GCSE Edexcel 计算机:算法考点精讲
Algorithms are the heartbeat of computer science. This guide covers the essential algorithmic concepts you need to master for the Edexcel GCSE Computer Science examination, including computational thinking, searching and sorting techniques, flowchart and pseudocode representation, and effective exam strategy. Each section is presented in both English and Chinese to support bilingual learners following the GCSE Edexcel specification (1CP2).
算法是计算机科学的核心。本指南涵盖了你为 Edexcel GCSE 计算机科学考试必须掌握的基本算法概念,包括计算思维、搜索与排序技术、流程图和伪代码表示,以及有效的考试策略。每个部分均以中英双语呈现,帮助遵循 GCSE Edexcel 大纲 (1CP2) 的双语学习者。
1. What is an Algorithm? | 什么是算法?
An algorithm is a precise, step-by-step sequence of instructions designed to solve a specific problem or perform a task. It must have a clear start, a finite number of steps, well-defined inputs and outputs, and produce a result in a predictable way. Everyday examples include a recipe for baking a cake or the instructions to sort a pile of books by height.
算法是一系列精确、逐步的指令,旨在解决特定问题或执行任务。它必须有明确的起始、有限的步骤、定义良好的输入输出,并以可预测的方式产生结果。日常生活中的例子包括烤蛋糕的食谱,或者按高度排列一堆书的操作步骤。
In computer science, algorithms can be expressed using natural language, flowcharts, or pseudocode. A good algorithm is both correct and efficient. Correctness means it produces the right output for every valid input; efficiency is about using minimal time and memory. When you design an algorithm, aim for clarity, modularization, and the ability to handle edge cases.
在计算机科学中,算法可以用自然语言、流程图或伪代码表示。好的算法既正确又高效。正确性意味着对于每个有效输入都产生正确的输出;效率则关系到使用最少的时间和内存。在设计算法时,要追求清晰性、模块化,并具备处理边界情况的能力。
2. Computational Thinking | 计算思维
Computational thinking provides a methodology to approach complex problems. It consists of four cornerstones: decomposition, pattern recognition, abstraction, and algorithm design. Decomposition involves breaking a large problem into smaller, manageable parts. Pattern recognition spots similarities with previously solved problems. Abstraction focuses on the relevant details, ignoring the unnecessary. Finally, algorithm design uses these insights to create a systematic solution.
计算思维提供了解决复杂问题的方法论。它包含四个基石:分解、模式识别、抽象和算法设计。分解是将大问题拆分成更小、可管理的部分;模式识别找出与已解决问题的相似点;抽象关注相关的细节而忽略不必要的信息;最后,算法设计利用这些洞见来创建系统化的解决方案。
In Edexcel examinations, you may be asked to apply computational thinking to a real-world scenario. For example, developing a program to manage a library system would involve decomposing into modules (catalog, borrowing, returns), recognising patterns (checking user ID, due dates), abstracting away hardware details, and designing algorithms for searching and sorting book records.
在 Edexcel 考试中,你可能会被要求将计算思维应用于现实场景。例如,开发一个图书馆管理系统需要将项目分解为模块(编目、借阅、归还),识别模式(检查用户ID、到期日),抽离硬件细节,并设计搜索和排序图书记录的算法。
3. Representing Algorithms: Flowcharts | 算法表示:流程图
Flowcharts visually represent algorithms using standard symbols connected by arrows to show the flow of control. The key symbols you must recognise and use for Edexcel GCSE are: oval (start/stop), parallelogram (input/output), rectangle (process), diamond (decision), and arrow lines (direction of flow). Each symbol has a specific meaning, and flowcharts always begin with a start oval and end with a stop oval.
流程图使用标准符号和箭头来直观地表示算法,用以展示控制流程。对于 Edexcel GCSE,你必须识别和使用的关键符号包括:椭圆形(开始/结束)、平行四边形(输入/输出)、矩形(处理)、菱形(判断)和箭线(流程方向)。每个符号都有特定含义,流程图总是以开始椭圆开始,以结束椭圆结束。
- Oval: indicates the start or end of the algorithm. | 椭圆形:表示算法的开始或结束。
- Parallelogram: used for input or output operations, such as READ or PRINT. | 平行四边形:用于输入或输出操作,比如 READ 或 PRINT。
- Rectangle: represents a process or operation, such as setting a variable or performing a calculation. | 矩形:表示一个过程或操作,例如赋值变量或执行计算。
- Diamond: decision point with a Boolean condition; flow splits into YES/TRUE or NO/FALSE branches. | 菱形:带有布尔条件的判断点;流程分为是/真或否/假分支。
When drawing flowcharts, ensure that all decision branches eventually rejoin the main flow. Use clear, unambiguous labels and avoid crossing lines wherever possible. Exam questions often ask you to complete a partially drawn flowchart or to trace the output for given inputs.
绘制流程图时,要确保所有判断分支最终汇入主流。使用清晰、无歧义的标签,并尽可能避免线条交叉。考试题目经常要求你补全部分绘制的流程图,或针对给定输入追踪输出。
4. Representing Algorithms: Pseudocode | 算法表示:伪代码
Pseudocode is a simple, human-readable notation that describes the logic of an algorithm without the strict syntax of a programming language. Edexcel uses a specific pseudocode style that you should adopt in exams. It includes keywords like SET ... TO ..., INPUT, OUTPUT, IF ... THEN ... ELSE ... ENDIF, WHILE ... DO ... ENDWHILE, and FOR ... TO ... NEXT.
伪代码是一种简单、可读的符号,用来描述算法的逻辑,而无须遵守编程语言的严格语法。Edexcel 使用特定的伪代码风格,你在考试中应采用该风格。它包括诸如 SET ... TO ...、INPUT、OUTPUT、IF ... THEN ... ELSE ... ENDIF、WHILE ... DO ... ENDWHILE 和 FOR ... TO ... NEXT 等关键词。
Example: an algorithm to print even numbers from 2 to 10:
SET number TO 2
WHILE number <= 10 DO
OUTPUT number
SET number TO number + 2
ENDWHILE
示例:输出从2到10的偶数的算法:
将 number 设为 2
当 number ≤ 10 执行
输出 number
将 number 设为 number + 2
循环结束
Indentation is used to show structure. A common mistake is missing the ENDWHILE, ENDIF or NEXT statements, so always check that you have properly closed every block. When writing pseudocode for searching or sorting, Edexcel expects you to follow a consistent approach similar to the official reference pseudocode.
缩进用于展示结构。常见错误是遗漏 ENDWHILE、ENDIF 或 NEXT 语句,因此要始终检查是否正确关闭了每个代码块。在编写搜索或排序的伪代码时,Edexcel 希望你采用与官方参考伪代码一致的方式。
5. Trace Tables | 跟踪表
A trace table is a manual tool used to test an algorithm by recording the values of variables at each execution step. It helps identify logic errors and understand how the algorithm transforms input into output. Columns represent variables, conditions, and output; each row corresponds to one step or iteration. Trace tables are especially useful for loops and decision structures.
跟踪表是一种手工工具,通过记录每一步执行时变量的值来测试算法。它有助于识别逻辑错误,并理解算法如何将输入转换为输出。列代表变量、条件和输出;每一行对应一个步骤或一次迭代。跟踪表对于循环和判断结构特别有用。
Suppose you have an algorithm that counts the number of positive integers entered until a negative number is input. The trace table would include columns for the input value, a count variable, and the condition tested. You fill in the table line by line as you simulate the algorithm. In the exam, you may be given an incomplete trace table and asked to supply the missing entries.
假设有一个算法,用于统计输入的正整数个数,直到输入负数为止。跟踪表中应包含输入值、计数变量以及所测试的条件等列。在模拟算法时,逐行填写表格。在考试中,你可能会拿到不完整的跟踪表,并被要求补充缺失的条目。
Always initialise variables before entering a loop. For a FOR loop, you record the loop counter's start, update, and check against the final value. For a WHILE loop, trace the condition before each iteration. Accurate trace tables are a straightforward way to earn marks—just be systematic.
在进入循环前,务必初始化变量。对于 FOR 循环,要记录循环计数器的起始值、更新值,并与终值进行比较。对于 WHILE 循环,在每次迭代前追踪条件。准确的跟踪表是获得分数的直接方法——只需系统化地进行即可。
6. Linear Search | 线性搜索
Linear search scans each element of a list one by one, from the first to the last, until the target value is found or the end is reached. It does not require the list to be sorted. The algorithm is simple: start at index 0, compare the current element with the search key, and if they match, return the index; otherwise, move to the next element.
线性搜索逐一扫描列表中的每个元素,从第一个到最后一个,直到找到目标值或到达末尾。它不要求列表有序。算法很简单:从索引0开始,将当前元素与搜索键比较,若匹配则返回索引;否则移至下一个元素。
Pseudocode for linear search (list of n elements, search item):
SET found TO FALSE
SET index TO 0
WHILE index < n AND found = FALSE DO
IF list[index] = item THEN
SET found TO TRUE
ELSE
SET index TO index + 1
ENDIF
ENDWHILE
IF found THEN OUTPUT index ELSE OUTPUT -1
线性搜索伪代码(n个元素的列表,搜索项):
将 found 设为 FALSE
将 index 设为 0
当 index < n 且 found = FALSE 时执行
如果 list[index] = item 那么
将 found 设为 TRUE
否则
将 index 加 1
结束如果
循环结束
如果 found 为 TRUE 则输出 index,否则输出 -1
The worst-case scenario requires n comparisons. Linear search is practical for small or unsorted data sets. However, for large sorted lists, binary search is dramatically more efficient. Edexcel expects you to compare both methods and choose the appropriate one based on the problem context.
最坏情况需要 n 次比较。线性搜索适用于小型或未排序的数据集。然而,对于大型有序列表,二分搜索的效率要高得多。Edexcel 期望你比较这两种方法,并根据问题语境选择合适的算法。
7. Binary Search | 二分搜索
Binary search works on a sorted list by repeatedly dividing the search interval in half. It compares the target value with the middle element. If the target equals the middle, the search finishes. If the target is smaller, the search continues in the lower half; if larger, in the upper half. This process repeats until the target is found or the interval is empty.
二分搜索作用于有序列表,通过反复将搜索区间减半来工作。它将目标值与中间元素进行比较。如果目标等于中间值,搜索结束。如果目标较小,则在下半区继续搜索;如果较大,则在上半区继续搜索。此过程重复进行,直到找到目标或区间为空。
, first mid=7 (>5), so consider left half [2,3,5]; new mid=3 (<5), right half [5] → found.
示例:在 [2,3,5,7,11,13,17] 中搜索 7。索引中点为 (0+6)//2 = 3,值 7 匹配。若在同一列表中搜索 5,首先 mid=7 (>5),考虑左半 [2,3,5];新 mid=3 (<5),右半 [5] → 找到。
Pseudocode outline (low and high indices):
SET low TO 0, high TO n-1, found TO FALSE
WHILE low <= high AND found = FALSE DO
mid ← (low + high) DIV 2
IF list[mid] = item THEN found = TRUE
ELSE IF list[mid] < item THEN low = mid + 1
ELSE high = mid − 1
ENDIF
ENDWHILE
伪代码概要(低位索引与高位索引):
将 low 设为 0,high 设为 n-1,found 设为 FALSE
当 low ≤ high 且 found = FALSE 时执行
mid ← (low + high) DIV 2
如果 list[mid] = item 那么 found ← TRUE
否则如果 list[mid] < item 那么 low ← mid + 1
否则 high ← mid − 1
结束如果
结束循环
Binary search cuts the problem size by half each time, so it requires only about log₂(n) comparisons. It is far superior for large, sorted datasets but it demands an extra preprocessing step – sorting – which itself can be costly.
二分搜索每次将问题规模减半,因此仅需大约 log₂(n) 次比较。对于大型有序数据集,它优越得多,但需要一个额外的预处理步骤——排序——而其本身也可能代价高昂。
8. Bubble Sort | 冒泡排序
Bubble sort repeatedly steps through a list, compares adjacent elements, and swaps them if they are in the wrong order. Each pass places the next largest element into its correct final position—like a bubble rising to the surface. The algorithm stops when a complete pass occurs with no swaps.
冒泡排序反复遍历列表,比较相邻元素,若顺序错误则交换它们。每一趟将次大的元素放到其正确的最终位置——就像气泡浮上水面。当一整趟遍历没有发生交换时,算法停止。
Typical pseudocode:
SET n TO length of list
SET swapped TO TRUE
WHILE swapped = TRUE DO
swapped ← FALSE
FOR i FROM 0 TO n-2 DO
IF list[i] > list[i+1] THEN
SWAP list[i] AND list[i+1]
swapped ← TRUE
ENDIF
ENDFOR
n ← n − 1
ENDWHILE
典型伪代码:
将 n 设为列表长度
将 swapped 设为 TRUE
当 swapped = TRUE 时执行
swapped ← FALSE
对于 i 从 0 到 n-2
如果 list[i] > list[i+1] 那么
交换 list[i] 和 list[i+1]
swapped ← TRUE
结束如果
结束循环
n ← n − 1
结束循环
Bubble sort is simple to understand but inefficient for large lists. In the worst case, it makes approximately n²/2 comparisons. However, it performs well on almost-sorted lists and is often used to illustrate the concept of a sorting algorithm. The Edexcel specification expects you to trace bubble sort in a trace table and identify the number of swaps and passes.
冒泡排序易于理解,但对于大型列表效率低下。在最坏情况下,大约需要 n²/2 次比较。不过,它在近乎有序的列表上表现良好,并常被用来展示排序算法的概念。Edexcel 大纲要求你能够在跟踪表中追踪冒泡排序,并识别交换次数和遍历次数。
9. Merge Sort | 归并排序
Merge sort is a divide-and-conquer algorithm. It recursively splits the list into two halves until each sublist contains a single element (which is trivially sorted). Then it merges the sublists back together in a sorted order. The merging stage compares the smallest remaining elements of the two halves and builds the sorted result.
归并排序是一种分治算法。它递归地将列表分成两半,直到每个子列表只包含一个元素(显然有序)。然后它按照顺序将子列表合并回去。合并阶段比较两半中剩余的最小元素,并构建已排序的结果。
For example, [38,27,43,3,9,82,10] splits into [38,27,43,3] and [9,82,10]; the left half splits further into [38,27] and [43,3], and so on. When merging sorted sublists, pointers track the current position in each half. Merge sort guarantees O(n log n) performance in all cases, making it much faster than bubble sort for large n.
例如,[38,27,43,3,9,82,10] 分为 [38,27,43,3] 和 [9,82,10];左半部分进一步分为 [38,27] 和 [43,3],依此类推。合并已排序的子列表时,使用指针跟踪各半的当前位置。在所有情况下,归并排序都能保证 O(n log n) 的性能,对于大规模 n,它远比冒泡排序快。
. Otherwise, find the midpoint, recursively sort left and right halves, then merge. Merge sorting requires additional memory to hold temporary arrays during merging.
Edexcel 可能会要求你展示在给定列表上进行归并排序的阶段,或写出伪代码概要。关键步骤:如果列表长度 ≤ 1,则已排序。否则,找到中点,递归排序左半和右半,然后合并。归并排序在合并时需要额外的内存来存放临时数组。
10. Insertion Sort | 插入排序
Insertion sort builds the sorted list one element at a time. It repeatedly takes the next unsorted element and inserts it into its correct position within the already sorted portion. The algorithm is analogous to sorting a hand of playing cards: you pick up a card and place it in the right spot among the cards you already hold.
插入排序每次构建一个有序列表。它反复取下一个未排序元素,并将其插入到已排序部分的正确位置。该算法类似于整理一手扑克牌:你拿起一张牌,并将其放到手中已有的正确位置上。
Pseudocode for an array of n items (index from 0):
FOR i FROM 1 TO n-1 DO
current ← list[i]
j ← i − 1
WHILE j >= 0 AND list[j] > current DO
list[j+1] ← list[j]
j ← j − 1
ENDWHILE
list[j+1] ← current
ENDFOR
长度为 n 的数组(索引从0开始)的伪代码:
对于 i 从 1 到 n-1
current ← list[i]
j ← i − 1
当 j ≥ 0 且 list[j] > current 时执行
list[j+1] ← list[j]
j ← j − 1
结束循环
list[j+1] ← current
结束循环
Insertion sort performs well on small or nearly sorted lists. Its average and worst-case time complexity is O(n²), similar to bubble sort, but it often requires fewer swaps. In Edexcel questions, you may be asked to trace an insertion sort, identifying the comparisons and shifts that occur as the algorithm progresses.
插入排序在小列表或近乎有序的列表上表现良好。其平均和最坏情况时间复杂度为 O(n²),与冒泡排序相似,但通常所需交换更少。在 Edexcel 考题中,你可能需要追踪插入排序,识别算法推进过程中的比较和位移。
11. Comparing Algorithm Efficiency | 算法效率比较
Understanding why one algorithm outperforms another is crucial. We often compare algorithms in terms of time complexity – a measure of how the number of operations grows with input size n. While formal Big O notation is not heavily examined, you should know that constant time O(1) is ideal, linear O(n) grows proportionally, and quadratic O(n²) grows much faster.
理解为什么一种算法优于另一种至关重要。我们经常根据时间复杂度来比较算法——这是衡量操作次数随输入规模 n 增长的指标。虽然不会深入考查正式的大O符号,但你应知道常数时间 O(1) 最理想,线性 O(n) 成比例增长,而二次方 O(n²) 增长快得多。
For searching: linear search is O(n), binary search is O(log n). For sorting: bubble, insertion, and simple selection sorts are O(n²) in the worst case; merge sort is O(n log n). The logarithmic base 2 growth means that doubling n adds only one extra step for binary search, making it far superior on huge sorted lists.
对于搜索:线性搜索为 O(n),二分搜索为 O(log n)。对于排序:冒泡排序、插入排序和简单选择排序在最坏情况下为 O(n²);归并排序为 O(n log n)。以2为底的对数增长意味着,当 n 翻倍时,二分搜索仅多一步,这使其在巨大的有序列表上大大胜出。
| Algorithm | Worst-case | Requires sorted data? |
| Linear Search | O(n) | No |
| Binary Search | 广告 / Sponsored 培生爱德思计算机科学学生用书教材Pearson Edexcel International GCSE Computer… 计算机 备考教辅 · 正版现货 · 与本文内容相关 查看详情 / View on Taobao参考价 ¥349.0
更多咨询请联系16621398022(同微信) 备考资讯每日更新,关注不错过 考纲变化 · 科目分析 · 学习方法 ![]() 在微信里长按二维码识别关注 或截图后用「扫一扫 → 相册」选择本图 公众号:tutorhao |
