📚 GCSE Edexcel Computer Science: Mastering Arrays Exam Guide | GCSE Edexcel 计算机:数组 考点精讲
Arrays are one of the fundamental data structures in GCSE Computer Science. They allow you to store multiple items of the same data type under a single identifier, using an index to access each value. In the Edexcel specification, you are expected to declare, initialise, traverse, and manipulate both one-dimensional and two-dimensional arrays using pseudocode or a high-level language. This article breaks down every key concept you need to master for the exam.
数组是 GCSE 计算机科学中最基础的数据结构之一。它允许你使用单个标识符存储多个相同数据类型的元素,并通过索引来访问每个值。在 Edexcel 考试大纲中,你需要掌握一维和二维数组的声明、初始化、遍历和操作,且通常会以伪代码或高级语言的形式出现。本文将逐一解析你必须掌握的每一个核心考点。
1. What Is an Array? | 什么是数组?
An array is a collection of elements, all of the same data type, stored contiguously in memory. Each element is identified by a numerical index, typically starting at 0. Arrays can be one-dimensional (a list) or two-dimensional (a grid or table). They provide an efficient way to organise related data without creating dozens of separate variables.
数组是一组相同数据类型的元素,在内存中连续存储。每个元素通过数值索引来标识,索引通常从 0 开始。数组可以是一维的(如列表),也可以是二维的(如网格或表格)。使用数组能高效地组织相关数据,而无需创建十几个单独的变量。
In Edexcel pseudocode, array indices start at 0, just like in Python. This is a crucial detail because many past paper questions test your ability to trace code that uses index values correctly.
在 Edexcel 伪代码中,数组索引从 0 开始,与 Python 一致。这一点很关键,因为许多历年真题会考查你是否能正确追踪使用索引值的代码。
2. Declaring and Initialising Arrays | 数组的声明与初始化
Before using an array, you must declare it and assign initial values. In Edexcel pseudocode, you often use a statement such as DECLARE scores : ARRAY[0:4] OF INTEGER to create an array that can hold 5 integers (indices 0 to 4). You can then assign values individually.
在使用数组之前,你必须先声明它并赋予初始值。在 Edexcel 伪代码中,你通常会看到类似 DECLARE scores : ARRAY[0:4] OF INTEGER 的语句,它创建了一个可容纳 5 个整数的数组(索引 0 到 4)。随后你可以逐个为元素赋值。
You may also initialise an array in a single line, e.g. scores ← [12, 8, 19, 4, 7]. This is closer to Python syntax and is perfectly acceptable in the exam. Make sure you can convert between declaration styles and understand the meaning of the lower and upper bounds.
你也可以在一行内初始化数组,例如 scores ← [12, 8, 19, 4, 7]。这种写法更接近 Python,在考试中同样被认可。请务必能自如转换各种声明风格,并理解下标上界和下界的含义。
3. Accessing Array Elements | 访问数组元素
You refer to an individual element using the array name followed by the index in square brackets: scores[2] gives the third element. Since indices start at 0, the first element is scores[0] and the last is scores[4] for a 5-element array. Understanding zero-based indexing is essential for writing correct loops.
要引用某个元素,需在数组名后跟上方括号内的索引:scores[2] 表示第三个元素。由于索引从 0 开始,对于长度为 5 的数组,第一个元素是 scores[0],最后一个是 scores[4]。理解基于 0 的索引机制对于编写正确的循环至关重要。
In exam traces, you will often see statements like PRINT scores[0] or value ← sales[i]. Always check the current value of the index variable when stepping through code.
在考试的手工执行题中,你经常会看到 PRINT scores[0] 或 value ← sales[i] 这样的语句。在逐行模拟执行时,一定要随时确认索引变量的当前值。
4. Modifying Array Elements | 修改数组元素
You can change the content of an array by assigning a new value to a specific index: scores[3] ← 15. Unlike many immutable data types, array elements are mutable, meaning you can overwrite them as often as needed while the program runs.
你可以通过向特定索引赋予新值来修改数组的内容:scores[3] ← 15。与许多不可变的数据类型不同,数组元素是可变的,这意味着在程序运行过程中你可以随时覆盖它们。
Be careful with array bounds: attempting to modify scores[5] when the array was declared with indices 0-4 will result in an 'index out of range' error. The exam expects you to predict such runtime errors.
要小心数组边界:如果数组声明时索引范围为 0 到 4,却尝试修改 scores[5],将会导致“索引越界”错误。考试要求你能够预测这类运行时错误的发生。
5. Looping Through Arrays | 遍历数组
A FOR loop is the most common way to process every element in an array. For example, FOR index ← 0 TO 4 lets you access scores[index] on each iteration. The loop counter acts as the array index, and you can read or update elements inside the loop body.
FOR 循环是处理数组中所有元素的最常用方式。例如,FOR index ← 0 TO 4 可以在每次迭代中访问 scores[index]。循环计数器充当数组索引,你可以在循环体内读取或更新元素。
An alternative approach uses a FOR EACH loop, which does not require an explicit index: FOR EACH value IN scores. This is convenient when you only need to read the elements, but be aware that you cannot modify the original array positions with this loop.
另一种方法是使用 FOR EACH 循环,它不需要显式写出索引:FOR EACH value IN scores。当你只需要读取元素时,这种写法很方便,但要注意,你无法通过这种循环修改原始数组中的位置。
6. Linear Search Using an Array | 使用数组实现线性查找
Linear search is a standard GCSE algorithm that scans through an array looking for a target value. The pseudocode sets a flag to false, then iterates through each index. If array[i] = target, the flag becomes true and a message is output. After the loop, the flag indicates whether the item was found.
线性查找是 GCSE 中的标准算法,它通过遍历数组来寻找目标值。伪代码通常先设置一个标志位为 false,然后遍历每一个索引。如果 array[i] = target,标志位变为 true 并输出结果。循环结束后,通过标志位即可判断是否找到该元素。
Edexcel questions might ask you to complete a linear search algorithm or to trace it with a given dataset. You should be able to explain why this algorithm is considered inefficient for large arrays (O(n) complexity) but perfectly fine for small ones.
Edexcel 的考题可能要求你补全线性查找算法,或根据给定数据集进行追踪。你应该能够解释为什么该算法对于大型数组效率较低(时间复杂度为 O(n)),但在小规模数据集上表现良好。
7. Introduction to Two-Dimensional Arrays | 二维数组简介
A two-dimensional array can be visualised as a table with rows and columns. In Edexcel pseudocode, you declare it as DECLARE grid : ARRAY[0:2, 0:3] OF INTEGER. This creates 3 rows and 4 columns. You access an element using two indices, e.g. grid[row, col].
二维数组可以看作一张带有行和列的表格。在 Edexcel 伪代码中,你会这样声明:DECLARE grid : ARRAY[0:2, 0:3] OF INTEGER。这将创建一个 3 行 4 列的数组。访问元素时需要两个索引,如 grid[row, col]。
Typical exam applications include storing a chessboard, a seating plan, or a high-score table. When you initialise such an array, you can list the rows: grid ← [[1,2,3],[4,5,6]]. Always count rows and columns carefully to avoid mistakes in writing nested loops.
考试中的典型应用包括存储棋盘、座位表或高分榜。初始化这类数组时,可以逐行列出数据:grid ← [[1,2,3],[4,5,6]]。务必仔细数清行数与列数,以免在编写嵌套循环时出错。
8. Nested Loops for Two-Dimensional Arrays | 二维数组的嵌套循环
To traverse every element of a 2D array, you need a FOR loop inside another FOR loop. The outer loop runs for each row, and the inner loop runs for each column in that row. For example, FOR row ← 0 TO 2 contains FOR col ← 0 TO 3.
要遍历二维数组中的每个元素,你需要在一个 FOR 循环内部再写一个 FOR 循环。外层循环控制行,内层循环控制该行中的每一列。例如,FOR row ← 0 TO 2 内部包含 FOR col ← 0 TO 3。
Exam questions often require you to output the contents 'row by row' or to sum all the values. You may also be asked to flip rows and columns, or to locate a specific value using a nested loop with a flag. Practice drawing the array as a grid to help you trace the code.
考题经常要求你“逐行”输出数组内容,或求所有元素之和。也可能要求你进行行列转置,或利用带标志位的嵌套循环定位特定值。建议你在草稿纸上画出表格进行追踪,这将有助于你理清逻辑。
9. Common Mistakes and How to Avoid Them | 常见错误及避免方法
One common error is confusing the length of the array with the last valid index. If an array has 10 elements, the indices run from 0 to 9. Writing a loop with FOR i ← 0 TO 10 will cause an index out-of-range error.
一个常见错误是混淆数组长度与最后一个有效索引。如果数组有 10 个元素,其索引范围是 0 到 9。如果写成 FOR i ← 0 TO 10 的循环,就会引发索引越界错误。
Another mistake is trying to use a string as an index. Indices must be integers. Also, forgetting to reset a flag variable before a search often leads to incorrect output. In the exam, always initialise your variables explicitly.
另一个错误是试图用字符串作为索引。索引必须是整数。此外,在搜索前忘记重置标志变量也常常导致输出错误。在考试中,请务必显式初始化所有变量。
10. Exam-Style Pseudocode Questions | 考试风格的伪代码题
You may be given a partially complete algorithm and asked to fill in the blanks. For instance: 'The array numbers contains 20 integers. Write a loop that outputs all values greater than 100.' Your answer should include a FOR loop from 0 to 19 and an IF statement inside it.
你可能会看到一道补全算法的题目。例如:“数组 numbers 包含 20 个整数。编写一段循环,输出所有大于 100 的值。”你的答案应包含一个从 0 到 19 的 FOR 循环,并在循环体内嵌套一个 IF 语句。
Other typical tasks include rewriting a program to use a 2D array, or predicting the contents of an array after a series of swaps. Always write out the array state at each step when tracing, and refer back to the exam board's pseudocode guide for syntax.
其他典型任务还包括用二维数组重写程序,或预测数组在经过一系列交换操作后的内容。做追踪题时,务必在每一步记录数组的状态,并参照考试局的伪代码指南使用正确语法。
11. Practical Applications in Python (for Reference) | Python 中的应用(供参考)
Although the exam may use pseudocode, many schools teach the concepts using Python. A Python list works as a one-dimensional array: scores = [12, 8, 19]. The len() function returns the number of elements, and a for i in range(len(scores)) loop lets you iterate by index.
尽管考试使用伪代码,但多数学校会借助 Python 进行教学。Python 中的列表可以充当一维数组:scores = [12, 8, 19]。len() 函数返回元素个数,你可以用 for i in range(len(scores)) 通过索引进行迭代。
For two-dimensional arrays, a list of lists is used: grid = [[1,2],[3,4]]. Accessing grid[0][1] gives the value 2. Python is zero-indexed, so it aligns perfectly with Edexcel pseudocode, making it an excellent tool for practising array algorithms.
对于二维数组,可以使用嵌套列表:grid = [[1,2],[3,4]]。访问 grid[0][1] 将得到值 2。Python 同样采用从 0 开始的索引,这与 Edexcel 伪代码完全一致,因此它是练习数组算法的绝佳工具。
12. Key Takeaways for the Exam | 考试关键要点
Arrays are a guaranteed topic on your Edexcel GCSE Computer Science paper. Remember that indices start at 0, loops must stay within bounds, and two-dimensional arrays require nested iteration. Practise writing algorithms such as linear search and total calculation until you can do them without hesitation.
数组是 Edexcel GCSE 计算机科学试卷中必考的主题。请牢记:索引从 0 开始,循环不得越界,二维数组需要嵌套迭代。反复练习线性查找、求和等算法,直到你能不假思索地写出它们。
When the exam presents you with an array question, first identify the data type, the bounds, and the purpose. Draw a small table if it helps. Then carefully step through any given code or construct your own solution. With consistent practice, array problems become reliable marks on your paper.
在考场上遇到数组题目时,首先识别数据类型、数组边界和程序目的。如有必要,可以画出小表格帮助思考。然后耐心地模拟执行给定代码,或构建你自己的解决方案。经过持续练习,数组题将是你试卷上最稳定的得分点。
Published by TutorHao | GCSE Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

或截图后用「扫一扫 → 相册」选择本图