← 返回资讯屏轩教育 · 行业资讯

GCSE Computer Science: Arrays – Key Concepts | GCSE 计算机:数组考点精讲

2026-07-14 21:38 · 本文部分内容由AI辅助创作

📚 GCSE Computer Science: Arrays – Key Concepts | GCSE 计算机:数组考点精讲

Arrays are one of the fundamental building blocks in programming and appear frequently in GCSE Computer Science exams. This guide unpacks the core concepts, indexing rules, common algorithms, and exam techniques you need to handle array questions with confidence.

数组是编程中最基本的构建模块之一,在 GCSE 计算机科学考试中频繁出现。本文将解析核心概念、索引规则、常见算法与备考技巧,帮助你自信应对数组相关题目。


1. What is an Array? | 什么是数组?

An array is a data structure that can hold a fixed number of elements, all of the same data type, under a single variable name. It is stored in contiguous memory locations, allowing each element to be accessed directly using its position, or index. Once an array is declared, its size cannot be changed during program execution. This makes arrays ideal for storing collections like test scores, temperature readings, or a list of names where fast, ordered access is needed.

数组是一种数据结构,它用一个变量名来容纳固定数量的元素,且所有元素必须为相同数据类型。数组在内存中连续存放,因此可以通过元素的位置(索引)直接访问任何一个元素。声明之后,数组的大小在程序运行期间不可更改。这使数组非常适合存储诸如测试成绩、温度读数或姓名列表等需要快速有序访问的数据集合。


2. Indexing in Arrays | 数组索引

Individual elements are identified by their index. In most modern programming languages and the pseudocode used by major GCSE exam boards, arrays are zero-indexed: the first element is at index 0, the second at index 1, and so on. For an array named scores holding 5 elements, valid indices are 0, 1, 2, 3, and 4. Using an index outside this range, such as scores[5], results in an index out-of-bounds error. A few legacy pseudocode styles use one-based indexing, but students must be comfortable with zero-based access because it is the default in languages like Python, Java, and C-style syntax.

数组中的每个元素通过索引来标识。在大多数现代编程语言以及 GCSE 主要考试局使用的伪代码中,数组采用从零开始的索引:第一个元素的索引为 0,第二个为 1,依此类推。对于一个名为 scores、包含 5 个元素的数组,有效索引为 0、1、2、3、4。使用范围外的索引(如 scores[5])会导致索引越界错误。少数旧式伪代码可能采用以 1 起始的索引,但学生必须熟悉从零开始的访问方式,因为 Python、Java 及类 C 语法语言均以此为默认。


3. Declaring and Initialising Arrays | 声明与初始化数组

An array must be declared before use, specifying its name, size, and the data type it will store. In pseudocode, you might see: DECLARE temperatures : ARRAY[1:7] OF REAL. This reserves space for seven real numbers. You can also initialise an array at declaration with a list of values: DECLARE days ← ['Mon','Tue','Wed','Thu','Fri']. In Python, which many schools use, a list acts as an array and can be created as marks = [85, 90, 78]. Exam trace tables often require you to interpret such declarations correctly.

数组在使用前必须声明,指明其名称、大小以及将要存储的数据类型。在伪代码中,可能会见到:DECLARE temperatures : ARRAY[1:7] OF REAL,这为七个实数预留了空间。也可以在声明时用一系列值进行初始化:DECLARE days ← ['Mon','Tue','Wed','Thu','Fri']。在许多学校使用的 Python 中,列表可以充当数组,通过 marks = [85, 90, 78] 创建。考试中的跟踪表题往往要求你能正确解读这些声明。


4. Accessing and Modifying Elements | 访问与修改元素

To read a value, use the array name followed by the index in square brackets, e.g., firstMark ← marks[0]. Writing a new value works the same way: marks[2] ← 95 replaces the third element with 95. Both operations are constant-time – they take the same time regardless of the array’s length. Always ensure the index is within bounds; otherwise, the program will crash.

要读取某个值,只需使用数组名后跟方括号内的索引,例如 firstMark ← marks[0]。写入新值的方式相同:marks[2] ← 95 会将第三个元素替换为 95。这两种操作均为常量时间——无论数组有多长,所用时间都一样。务必确保索引在范围内,否则程序会崩溃。


5. Iterating Through Arrays | 遍历数组

Processing every element is achieved with a loop. A FOR loop is ideal because the size of the array is known. The loop counter serves as the index:

FOR i ← 0 TO LEN(arr)-1
    OUTPUT arr[i]
ENDFOR

Some languages also provide a FOR EACH loop that directly yields each element: FOR EACH value IN arr. Iteration is essential for tasks such as computing totals, searching for a value, or applying a formula to each element.

处理每个元素要借助循环。由于数组大小已知,FOR 循环很理想。循环计数器可以充当索引:

FOR i ← 0 TO LEN(arr)-1
    OUTPUT arr[i]
ENDFOR

部分语言还提供 FOR EACH 循环,直接给出每个元素:FOR EACH value IN arr。遍历对于计算总和、搜索某个值或对每个元素施加公式等任务必不可少。


广告 / Sponsored

6. 1D and 2D Arrays | 一维与二维数组

A one‑dimensional (1D) array is a simple linear list, like a row of pigeonholes. A two‑dimensional (2D) array organises data in rows and columns, forming a grid. It needs two indices: row and column. For example, grid[2,3] could represent the element in the third column of the second row. Declaration in pseudocode: DECLARE board : ARRAY[1:8, 1:8] OF STRING. In Python, a 2D array is implemented as a list of lists, e.g., grid = [[1,2],[3,4]].

一维数组是一个简单的线性列表,就像一排信箱。二维数组将数据组织成行和列,形成网格,因此需要两个索引:行和列。例如 grid[2,3] 可表示第 2 行第 3 列的元素。伪代码中的声明:DECLARE board : ARRAY[1:8, 1:8] OF STRING。在 Python 中,二维数组以列表的列表实现,如 grid = [[1,2],[3,4]]。


7. Working with 2D Arrays | 使用二维数组

Accessing a 2D element requires two indices: value ← matrix[row, column]. To traverse the whole grid, nested loops are used – the outer loop iterates over rows, the inner loop over columns:

FOR r ← 0 TO numRows-1
    FOR c ← 0 TO numCols-1
        OUTPUT matrix[r,c]
    ENDFOR
ENDFOR

Keeping row and column indices distinct is crucial to avoid logic errors. Exam questions frequently ask you to trace 2D array code, initialise a grid, or calculate the sum of a given row.

访问二维元素需要两个索引:value ← matrix[row, column]。要遍历整个网格,须使用嵌套循环——外层循环处理行,内层循环处理列:

FOR r ← 0 TO numRows-1
    FOR c ← 0 TO numCols-1
        OUTPUT matrix[r,c]
    ENDFOR
ENDFOR

清晰区分行索引与列索引对避免逻辑错误至关重要。考试题常要求你跟踪二维数组代码、初始化网格或计算某行的总和。


8. Linear Search Using Arrays | 使用数组进行线性搜索

A linear search checks every element one by one until a match is found or the end of the array is reached. It works on both sorted and unsorted data. Pseudocode:

FOUND ← FALSE
FOR i ← 0 TO LEN(arr)-1
    IF arr[i] = searchValue THEN
        OUTPUT "Found at index", i
        FOUND ← TRUE
    ENDIF
ENDFOR
IF NOT FOUND THEN
    OUTPUT "Not found"
ENDIF

Linear search is simple but inefficient for large arrays. It is a frequently examined algorithm, often contrasted with binary search which requires a sorted array.

线性搜索逐个检查每一个元素,直到找到匹配项或到达数组末尾。它对已排序和未排序的数据都适用。伪代码:

FOUND ← FALSE
FOR i ← 0 TO LEN(arr)-1
    IF arr[i] = searchValue THEN
        OUTPUT "Found at index", i
        FOUND ← TRUE
    ENDIF
ENDFOR
IF NOT FOUND THEN
    OUTPUT "Not found"
ENDIF

线性搜索简单,但对大数组效率低下。这是常考的算法,常与需要排序的二分搜索作比较。


9. Finding Maximum and Minimum | 查找最大值/最小值

To locate the maximum, assume the first element is the largest, then scan the rest and update if a larger value appears:

maxVal ← arr[0]
FOR i ← 1 TO LEN(arr)-1
    IF arr[i] > maxVal THEN
        maxVal ← arr[i]
    ENDIF
ENDFOR

The logic for the minimum is identical, except the comparison uses <. This algorithm is the basis for tasks like “output the highest mark” or “find the coldest day”. It assumes the array contains at least one element – a safe assumption in GCSE contexts unless explicitly stated otherwise.

要找到最大值,先假设第一个元素最大,然后扫描其余元素,若出现更大的值则更新:

maxVal ← arr[0]
FOR i ← 1 TO LEN(arr)-1
    IF arr[i] > maxVal THEN
        maxVal ← arr[i]
    ENDIF
ENDFOR

最小值的逻辑完全相同,只需把比较符改为 <。该算法是“输出最高分数”或“找出最冷的一天”等题目的基础。它假定数组中至少有一个元素——在 GCSE 情景中,除非明确说明,这通常是一个安全的假设。


10. Advantages and Limitations | 数组的优势与局限性

Arrays provide constant-time random access: any element can be retrieved instantly via its index. They are memory-efficient because elements are packed tightly. However, a key limitation is their fixed size; you cannot append an element without creating a larger array and copying the data. Inserting or deleting an item in the middle requires shifting elements, which is slow. In many high‑level languages, dynamic structures like Python’s list or a vector overcome this, but the static array remains a core concept that underpins more complex structures.

数组提供常量时间的随机访问:通过索引可以瞬间取得任何元素。由于元素紧密排列,内存利用效率高。然而,一项关键局限是其固定大小;若不创建更大的数组并复制数据,就无法追加元素。在数组中间插入或删除元素需要搬移其他元素,速度较慢。在许多高级语言中,像 Python 的列表或向量等动态结构克服了这一点,但静态数组仍然是支撑更复杂结构的基础概念。


11. Programming Examples | 编程示例

Below are Python snippets – note that Python’s list behaves like an array. Exam pseudocode may differ, but the logic is transferable.

1D total:

marks = [78, 85, 92]
total = 0
for i in range(len(marks)):
    total += marks[i]
print("Total:", total)

2D row sum (first

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

广告 / Sponsored
培生爱德思计算机科学学生用书教材Pearson Edexcel International GCSE Computer…
计算机 备考教辅 · 正版现货 · 与本文内容相关
查看详情 / View on Taobao参考价 ¥349.0

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

备考资讯每日更新,关注不错过
考纲变化 · 科目分析 · 学习方法
扫码关注公众号 tutorhao
在微信里长按二维码识别关注
或截图后用「扫一扫 → 相册」选择本图
公众号:tutorhao