GCSE WJEC Computer Science: Algorithms Revision Guide | GCSE WJEC 计算机:算法考点精讲

📚 GCSE WJEC Computer Science: Algorithms Revision Guide | GCSE WJEC 计算机:算法考点精讲

Algorithms are the heart of computer science – they are step‑by‑step procedures for solving problems. In the WJEC GCSE Computer Science specification, you need to understand how to design, represent, and evaluate algorithms. This revision guide covers every key topic: from pseudocode and flowcharts to searching and sorting, as well as algorithmic thinking and exam techniques.

算法是计算机科学的核心——它们是一步一步解决问题的过程。在 WJEC GCSE 计算机科学考试大纲中,你需要理解如何设计、表示和评估算法。这份考点精讲涵盖了所有关键主题:从伪代码和流程图到查找和排序,再到算法思维和考试技巧。


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

An algorithm is a precise set of instructions that can be followed to solve a problem or complete a task. It must be unambiguous, finite, and effective – every step must be clear, the process must eventually stop, and it must produce the correct result when followed exactly.

算法是一组精确的指令,可以按照指令来解决问题或完成任务。它必须是无歧义的、有限的和有效的——每一步都必须清晰,过程最终必须停止,并且严格遵循时必须产生正确的结果。

Algorithms are independent of programming languages. The same logic can be implemented in Python, Java, or any other language. In GCSE WJEC, you are expected to create and interpret algorithms using pseudocode and flowcharts.

算法独立于编程语言。相同的逻辑可以用 Python、Java 或其他任何语言实现。在 GCSE WJEC 中,你需要使用伪代码和流程图创建并解释算法。


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

Pseudocode is a structured, plain‑English way to write algorithms. WJEC has its own style, but it is flexible. You will see keywords such as INPUT, OUTPUT, IF … THEN … ELSE … ENDIF, WHILE … ENDWHILE, and FOR … ENDFOR. Assignments use the ← symbol, and comparison operators are =, ≠, <, >, ≤, ≥.

伪代码是一种结构化、用普通英语书写算法的方式。WJEC 有自己的风格,但比较灵活。你会看到诸如 INPUTOUTPUTIF … THEN … ELSE … ENDIFWHILE … ENDWHILEFOR … ENDFOR 等关键词。赋值使用 ← 符号,比较运算符为 =、≠、<、>、≤、≥。

For example, a pseudocode snippet to add the numbers 1 to 10 could be:

例如,将数字 1 加到 10 的伪代码片段可以是:

sum ← 0
FOR i ← 1 TO 10
  sum ← sum + i
ENDFOR
OUTPUT sum

Always use indentation to show the body of loops and selections. This makes the logic easy to follow and is a requirement in WJEC mark schemes.

务必使用缩进来表示循环和选择结构的体。这使逻辑易于理解,也是 WJEC 评分标准中的要求。


3. Flowcharts | 流程图

Flowcharts use standard symbols to represent algorithm steps visually. The main symbols you need for WJEC are: an oval for ‘Start’ and ‘End’, a parallelogram for input/output, a rectangle for a process, and a diamond for a decision. Arrows show the flow of control.

流程图使用标准符号来直观地表示算法步骤。在 WJEC 中需要掌握的主要符号有:椭圆形代表“开始”和“结束”,平行四边形代表输入/输出,矩形代表处理步骤,菱形代表判断。箭头表示控制流程。

When drawing a flowchart, always make sure every decision has two labelled exits (for example ‘Yes’ and ‘No’). If a loop is needed, you can direct an arrow back to an earlier step. Flowcharts are excellent for visualising the logic before coding.

绘制流程图时,要确保每个判断有两个标记的出口(例如“是”和“否”)。如果需要循环,可以将箭头指回前面的步骤。流程图非常适合在编码前可视化逻辑。

A simple flowchart for a login check might start with an input box for a password, then a decision diamond testing if the password equals ‘admin’. If yes, output ‘Access granted’; if no, output ‘Access denied’ and then end.

一个简单的登录检查流程图可以从一个输入密码的方框开始,然后是一个判断菱形,测试密码是否等于 ‘admin’。如果相等,输出 ‘Access granted’;如果不相等,输出 ‘Access denied’,然后结束。


4. Linear Search | 线性查找

Linear search is the simplest way to find an item in a list. You look at each element one by one from the start until you either find the target or reach the end of the list. It works on unsorted data, but can be slow for long lists.

线性查找是在列表中查找项目的最简单方法。你从开头开始逐个检查每个元素,直到找到目标或到达列表末尾。它适用于未排序的数据,但对于长列表可能较慢。

In WJEC pseudocode, a linear search can be written as:

用 WJEC 伪代码,线性查找可以写成:

found ← false
i ← 0
WHILE i < LEN(list) AND found = false
  IF list[i] = target THEN
    found ← true
    OUTPUT i
  ELSE
    i ← i + 1
  ENDIF
ENDWHILE
IF found = false THEN
  OUTPUT “Not found”
ENDIF

In the worst case, linear search needs to examine every element. The maximum number of comparisons is n, where n is the length of the list.

在最坏情况下,线性查找需要检查每一个元素。最大比较次数为 n,其中 n 是列表的长度。


5. Binary Search | 二分查找

Binary search is a much faster search algorithm, but it only works on a sorted list. It repeatedly divides the search space in half by comparing the target with the middle element. If the target is smaller, it searches the left half; if larger, the right half.

二分查找是一种快得多的查找算法,但它只适用于已排序的列表。它通过将目标值与中间元素进行比较,反复将搜索空间减半。如果目标较小,就搜索左半部分;如果较大,就搜索右半部分。

The pseudocode for binary search uses three variables: low, high, and mid.

二分查找的伪代码使用三个变量:low、high 和 mid。

low ← 0
high ← LEN(list) – 1
found ← false
WHILE low ≤ high AND found = false
  mid ← (low + high) DIV 2
  IF list[mid] = target THEN
    found ← true
    OUTPUT mid
  ELSE IF list[mid] < target THEN
    low ← mid + 1
  ELSE
    high ← mid – 1
  ENDIF
ENDWHILE
IF found = false THEN
  OUTPUT “Not found”
ENDIF

Each comparison roughly halves the number of remaining elements. The worst‑case number of comparisons is about log₂(n), which is much smaller than n for large lists. For example, a list of 1,000,000 items needs at most 21 comparisons with binary search.

每次比较大致将剩余元素数量减半。最坏情况下的比较次数约为 log₂(n),对于大列表来说远小于 n。例如,一个包含 1,000,000 个项目的列表,使用二分查找最多需要 21 次比较。


6. Bubble Sort | 冒泡排序

Bubble sort repeatedly steps through the list, compares adjacent items, and swaps them if they are in the wrong order. Larger values ‘bubble up’ to the end of the list with each pass. It is a simple but inefficient algorithm for large data sets.

冒泡排序反复遍历列表,比较相邻项,如果它们顺序错误就交换它们。每一轮较大的值会“冒泡”到列表的末尾。它是一种简单但对于大数据集效率较低的算法。

A WJEC‑style bubble sort pseudocode with an optimisation (stopping early if no swaps occur) looks like this:

一种带有优化(如果没有发生交换则提前停止)的 WJEC 风格冒泡排序伪代码如下:

n ← LEN(list)
swapped ← true
WHILE swapped = true
  swapped ← false
  FOR i ← 0 TO n – 2
    IF list[i] > list[i+1] THEN
      SWAP list[i], list[i+1]
      swapped ← true
    ENDIF
  ENDFOR
ENDWHILE

Bubble sort performs about n²/2 comparisons and swaps in the worst case, so it is described as having O(n²) time complexity. For a list of 10 items it’s fine, but for 10,000 items it becomes very slow.

冒泡排序在最坏情况下大约执行 n²/2 次比较和交换,因此它的时间复杂度被描述为 O(n²)。对于 10 个项目的列表这还可以,但对于 10,000 个项目它会变得非常慢。


7. Insertion Sort | 插入排序

Insertion sort builds a sorted portion at the beginning of the list. It picks the next unsorted element and inserts it into its correct position within the already sorted part, shifting larger elements to the right as needed.

插入排序在列表起始处建立一个已排序的部分。它选取下一个未排序的元素,并将其插入已排序部分中的正确位置,必要时将较大的元素向右移动。

This algorithm works well for small or partially sorted lists. Its pseudocode is:

该算法对于小型或部分排序的列表效果很好。其伪代码为:

FOR i ← 1 TO LEN(list) – 1
  key ← list[i]
  j ← i – 1
  WHILE j ≥ 0 AND list[j] > key
    list[j+1] ← list[j]
    j ← j – 1
  ENDWHILE
  list[j+1] ← key
ENDFOR

Like bubble sort, insertion sort has O(n²) complexity in the worst case. However, in the best case (when the list is already sorted) it only makes n-1 comparisons, running in O(n) time.

与冒泡排序一样,插入排序在最坏情况下的复杂度为 O(n²)。但在最好情况下(列表已经排序),它只进行 n-1 次比较,运行时间为 O(n)。


8. Merge Sort | 归并排序

Merge sort uses a divide‑and‑conquer approach. It splits the list into two halves recursively until each sub‑list contains only one element. Then it repeatedly merges the sub‑lists, comparing the smallest elements each time, to build up a sorted list.

归并排序使用分治法。它递归地将列表分成两半,直到每个子列表只包含一个元素。然后它反复合并子列表,每次比较最小的元素,从而构建出排序好的列表。

A merge sort can be expressed at a high level as:

归并排序可以在高层次表述为:

PROCEDURE mergeSort(list)
  IF LEN(list) > 1 THEN
    mid ← LEN(list) DIV 2
    left ← first half of list
    right ← second half of list
    mergeSort(left)
    mergeSort(right)
    merge(left, right, list)
  ENDIF
ENDPROCEDURE

Merge sort has a time complexity of O(n log n) in all cases, which makes it much faster than bubble sort and insertion sort for large lists. Its main drawback is that it requires extra memory to hold the temporary sub‑lists.

归并排序在所有情况下的时间复杂度都是 O(n log n),这使得它对大列表比冒泡排序和插入排序快得多。它的主要缺点是需要额外的内存来存放临时子列表。


9. Comparing Algorithms: Efficiency | 算法比较:效率

Algorithm efficiency is measured by how the time or memory required grows as the input size n increases. In GCSE WJEC, you don’t need formal big‑O notation, but you do need to understand the difference between, for example, an n² algorithm and an n log n algorithm.

算法效率是根据所需时间或内存随输入大小 n 增加而增长的情况来衡量的。在 GCSE WJEC 中,你不需要严格的大 O 表示法,但你需要理解例如 n² 算法和 n log n 算法之间的区别。

Linear search is proportional to n, binary search to log n. Bubble and insertion sorts are proportional to n², whereas merge sort is proportional to n log n. Choosing the right algorithm for the data size can make a program dramatically faster.

线性查找与 n 成正比,二分查找与 log n 成正比。冒泡排序和插入排序与 n² 成正比,而归并排序与 n log n 成正比。根据数据大小选择合适的算法可以大大提高程序的速度。

Space efficiency is also important. Merge sort uses extra memory, while bubble sort and insertion sort sort the list in place, using very little extra space.

空间效率也很重要。归并排序使用额外的内存,而冒泡排序和插入排序可以原地排序,几乎不使用额外的空间。


10. Trace Tables & Dry Running | 追踪表与手动运行

A trace table is a tool used to step through an algorithm manually, recording the values of variables at each step. WJEC exam questions often ask you to complete a trace table for a given algorithm, proving you understand how it works.

追踪表是一种用于手动逐步执行算法并记录每一步变量值的工具。WJEC 考试题目常常要求你为给定的算法完成一个追踪表,以证明你理解其工作原理。

To dry‑run an algorithm, start with the initial input, then move through the instructions line by line. Whenever a variable changes, write the new value in the next row of the trace table. Be careful to follow the correct logic of loops and conditions.

手动运行算法时,从初始输入开始,然后逐行执行指令。每当某个变量发生变化时,在追踪表的下一行写下新值。要仔细遵循循环和条件的正确逻辑。

For example, tracing a linear search on the list [3, 7, 1, 9] looking for 7 would show i changing from 0 to 1, and found becoming true when list[1] is checked.

例如,在列表 [3, 7, 1, 9] 中追踪线性查找 7,会显示 i 从 0 变为 1,当检查 list[1] 时 found 变为 true。


11. Common Algorithmic Thinking | 常见算法思维

Algorithmic thinking involves breaking down problems into small, manageable parts. The key concepts are decomposition (splitting a task into smaller sub‑tasks), abstraction (ignoring unnecessary detail), and pattern recognition (spotting similarities with other problems).

算法思维涉及将问题分解成小的、可管理的部分。关键概念是分解(将任务拆分成更小的子任务)、抽象(忽略不必要的细节)以及模式识别(发现与其他问题的相似之处)。

In WJEC, you might be given an everyday problem – for instance, designing a robot to escape a maze – and be asked to write an algorithm using the thinking strategies above. This is also tested in the on‑screen programming exam, where you must design solutions before coding.

在 WJEC 中,你可能会被给到一个日常问题——比如,设计一个走出迷宫的机器人——并被要求使用上述思维策略编写算法。这在机考编程考试中也会考查,你需要先设计解决方案再编写代码。


12. Exam Tips & Summary | 考试提示与总结

When tackling an algorithm question, always read the problem carefully. If a trace table is required, set up the columns before you start. Show your working – even if you get the final output wrong, you can gain marks for correct steps.

在处理算法问题时,一定要仔细阅读题目。如果需要追踪表,在开始之前先设置好列。展示你的解题过程——即使最终输出错误,你也可能因正确的步骤而得分。

Practice writing pseudocode by hand without an IDE. WJEC exams expect neat, indented pseudocode with clear structure. Use the keywords like WHILE, ENDWHILE, IF, ENDIF consistently. Remember that binary search and merge sort rely on the data being sorted; if the question says the list is unsorted, you cannot use binary search directly.

在没有集成开发环境的情况下动手练习书写伪代码。WJEC 考试要求整洁、缩进清晰、结构明确的伪代码。统一使用 WHILE、ENDWHILE、IF、ENDIF 等关键词。记住二分查找和归并排序依赖于数据已经排序;如果题目说列表未排序,你就不能直接使用二分查找。

In the programming exam, think about the most efficient algorithm you know for the task, but also consider simplicity – a correct linear search scores marks, while a broken binary search scores none. Finally, revise algorithms alongside your programming project, applying each one to real code.

在编程考试中,思考你所知道的最高效算法,但同时也要考虑简单性——一个正确的线性查找可以得分,而有缺陷的二分查找则一分不得。最后,将算法与你自己的编程项目结合起来复习,把每个算法应用到实际代码中。

Mastering algorithms means mastering the problem‑solving core of computer science. With clear pseudocode, flowcharts, and understanding of efficiency, you are well prepared for the WJEC GCSE examination.

掌握算法意味着掌握计算机科学的问题解决核心。凭借清晰的伪代码、流程图和对效率的理解,你就为 WJEC GCSE 考试做好了充分准备。

Published by TutorHao | Computer Science Revision Series | aleveler.com

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

Comments

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

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

Exit mobile version