📚 A-Level WJEC Computer Science: Arrays Exam Essentials | A-Level WJEC 计算机:数组 考点精讲
Arrays are the most fundamental data structure in the WJEC A-Level Computer Science specification. This guide consolidates every essential concept: one-dimensional and multi-dimensional arrays, indexing, traversal, insertion and deletion operations, searching and sorting algorithms, and the distinction between static and dynamic arrays. Each section is designed to build confidence for both the written paper and the practical programming tasks.
数组是 WJEC A-Level 计算机科学大纲中最基础的数据结构。本指南整合了每一个核心概念:一维数组和多维数组、索引、遍历、插入与删除操作、搜索与排序算法,以及静态数组和动态数组的区别。每个部分都旨在为笔试和实践编程任务建立信心。
1. What is an Array? | 什么是数组?
An array is a collection of elements of the same data type, stored in contiguous memory locations. Each element can be accessed directly using an integer index. This allows efficient read and write operations in O(1) constant time.
数组是相同数据类型元素的集合,存储在连续的内存位置中。每个元素可以通过整数索引直接访问。这使得读取和写入操作能在 O(1) 常数时间内高效完成。
The size of a static array is fixed at compile time and cannot be altered during program execution. In WJEC pseudocode, an array might be declared as ARRAY scores[10] OF INTEGER.
静态数组的大小在编译时确定,程序执行期间不可更改。在 WJEC 伪代码中,数组可能声明为 ARRAY scores[10] OF INTEGER。
Arrays are zero-indexed by default in most programming languages examined by WJEC, meaning the first element is at index 0 and the last at index n−1.
在 WJEC 考查的大多数编程语言中,数组默认采用零基索引,即第一个元素位于索引 0,最后一个元素位于索引 n−1。
2. Array Indexing | 数组索引
Direct access to an element is achieved by specifying the array name and the index enclosed in square brackets, for example scores[2]. This index must be an integer within the valid range 0 to length−1.
通过指定数组名和方括号内的索引即可直接访问元素,例如 scores[2]。索引必须是位于有效范围 0 到 length−1 之间的整数。
Using an index outside this range causes a runtime “index out of bounds” error. WJEC questions frequently ask about the consequences of invalid index access in trace-table exercises.
使用超出此范围的索引会导致运行时“索引越界”错误。WJEC 试题经常在跟踪表练习中询问无效索引访问的后果。
In a zero-indexed array of size n, the valid indices are mathematically represented as:
在一个大小为 n 的零索引数组中,有效索引的数学表示为:
0, 1, 2, …, n−1
3. Declaring and Initialising Arrays | 声明与初始化数组
WJEC pseudocode uses explicit declarations to define arrays. A one-dimensional array of 5 integers is declared as ARRAY nums[5] OF INTEGER. Initialisation can be done element by element or using a loop.
WJEC 伪代码使用显式声明来定义数组。一个包含 5 个整数的一维数组声明为 ARRAY nums[5] OF INTEGER。可以用逐个元素赋值或循环来完成初始化。
In Python (often used in the coursework component), a list can be used as a dynamic array, e.g. temps = [0]*7 creates a list of seven zeros. VB.NET uses Dim arr(4) As Integer, which creates an array of 5 elements (0 to 4).
在 Python(课程作业中常用)中,列表可用作动态数组,例如 temps = [0]*7 创建一个包含七个零的列表。VB.NET 使用 Dim arr(4) As Integer,这会创建一个包含 5 个元素(0 到 4)的数组。
Examiners may ask you to initialise an array with specific values, such as the first ten Fibonacci numbers. A combination of assignment statements or a FOR loop is expected.
考官可能会要求你用一个特定值序列初始化数组,例如前十个斐波那契数。此时需要使用赋值语句或 FOR 循环的组合。
4. Traversing Arrays with Loops | 使用循环遍历数组
Traversal means visiting every element of an array, typically from the first index to the last. A FOR loop is the most common control structure used:
遍历意味着访问数组的每一个元素,通常从第一个索引到最后一个索引。FOR 循环是最常用的控制结构:
FOR i ← 0 TO LEN(arr)−1
OUTPUT arr[i]
ENDFOR
You must be able to write algorithms that traverse an array to compute aggregates such as sum, average, maximum, or minimum. For example, finding the maximum involves initialising a variable with the first element and then comparing each subsequent element.
你必须能够编写遍历数组的算法来计算总和、平均值、最大值或最小值等聚合量。例如,查找最大值需要用一个变量初始化为第一个元素,然后依次比较后续的每个元素。
WJEC trace-table questions often require you to simulate a traversal algorithm step by step, recording the values of the loop counter and the array elements being accessed.
WJEC 跟踪表问题通常要求你逐步模拟遍历算法,记录循环计数器和被访问数组元素的值。
5. Multi-dimensional Arrays | 多维数组
A two-dimensional array can be visualised as a table with rows and columns, declared as ARRAY matrix[3][4] OF REAL for a 3×4 grid. Elements are accessed using two indices, e.g. matrix[1][2].
二维数组可以可视化为一个包含行和列的表格,对于一个 3×4 的网格,声明为 ARRAY matrix[3][4] OF REAL。元素通过两个索引访问,例如 matrix[1][2]。
Nested loops are essential for processing two-dimensional arrays. An outer loop controls the row index, and an inner loop controls the column index. This pattern is used for tasks like summing all elements or transposing a matrix.
嵌套循环是处理二维数组所必需的。外层循环控制行索引,内层循环控制列索引。此模式用于诸如对所有元素求和或转置矩阵的任务。
WJEC may provide a memory-mapped representation of a 2D array, showing how rows are stored sequentially in memory. For row-major order, the address of element [i][j] is calculated as: base + (i × number_of_columns + j) × element_size.
WJEC 可能会提供二维数组的内存映射表示,展示行如何在内存中连续存储。对于行主序,元素 [i][j] 的地址计算为:基地址 + (i × 列数 + j) × 元素大小。
6. Array Operations: Insertion | 数组操作:插入
Inserting a new element into a static array requires shifting existing elements to the right to make space. If the array is full, insertion is impossible without overwriting data; this limitation is frequently tested.
在静态数组中插入新元素需要将现有元素向右移动以腾出空间。如果数组已满,则无法插入而不覆盖数据;这个限制经常被考查。
The algorithm for insertion at a specific index k works as follows:
在特定索引 k 处插入的算法如下:
FOR i ← lastIndex DOWNTO k
arr[i+1] ← arr[i]
ENDFOR
arr[k] ← newValue
lastIndex ← lastIndex + 1
You must be careful to shift elements starting from the end of the used portion, otherwise you will overwrite elements before they are moved. This is a classic pitfall highlighted in WJEC mark schemes.
你必须十分小心地从已使用部分的末尾开始移动元素,否则在元素被移动之前就会覆盖它们。这是 WJEC 评分方案中强调的经典易错点。
7. Array Operations: Deletion | 数组操作:删除
Deleting an element from a static array involves shifting all subsequent elements one position to the left, effectively overwriting the element to be deleted. The last position is then considered unused.
从静态数组中删除元素涉及将所有后续元素向左移动一个位置,从而有效地覆盖要删除的元素。然后最后一个位置被视为未使用。
The deletion algorithm for index k is:
删除索引 k 处元素的算法为:
FOR i ← k TO lastIndex−1
arr[i] ← arr[i+1]
ENDFOR
lastIndex ← lastIndex − 1
This operation does not physically erase the element; it merely reduces the logical size of the array. WJEC questions often ask you to draw the state of the array after a deletion operation.
此操作并不会物理擦除该元素;它只是减少了数组的逻辑大小。WJEC 问题经常要求你绘制删除操作后数组的状态。
8. Searching: Linear Search | 搜索:线性搜索
Linear search examines each element in sequence until the target is found or the end of the array is reached. Its time complexity is O(n) in the worst case. It works on both sorted and unsorted arrays.
线性搜索按顺序检查每个元素,直到找到目标或达到数组末尾。其最坏情况下的时间复杂度为 O(n)。它适用于已排序和未排序的数组。
The pseudocode for a standard linear search with an early exit is:
带提前退出的标准线性搜索伪代码为:
found ← FALSE
i ← 0
WHILE i < LEN(arr) AND found = FALSE
IF arr[i] = target THEN
found ← TRUE
OUTPUT i
ELSE
i ← i + 1
ENDIF
ENDWHILE
Linear search is the only option when the array is not sorted, a constraint often explored in WJEC scenario-based questions.
当数组未排序时,线性搜索是唯一的选择,这是 WJEC 场景题中常探讨的约束条件。
9. Searching: Binary Search | 搜索:二分搜索
Binary search is a divide-and-conquer algorithm that requires the array to be sorted in ascending order. It repeatedly divides the search interval in half, achieving O(log n) time complexity.
二分搜索是一种分治算法,要求数组按升序排列。它反复将搜索区间减半,实现 O(log n) 时间复杂度。
The algorithm maintains three pointers: low, high, and mid. The middle index is calculated using integer division:
该算法维护三个指针:low、high 和 mid。中间索引使用整数除法计算:
mid ← (low + high) DIV 2
If the target equals the middle element, the search ends. If the target is smaller, the right half is discarded (high ← mid − 1). If larger, the left half is discarded (low ← mid + 1). The process repeats until found or low > high.
如果目标等于中间元素,搜索结束。如果目标较小,则舍弃右半部分(high ← mid − 1)。如果较大,则舍弃左半部分(low ← mid + 1)。重复此过程直到找到目标或 low > high。
WJEC exam questions frequently require a trace of binary search on a given sorted list, showing each value of low, mid, high at every iteration.
WJEC 考试题经常要求对给定排序列表进行二分搜索的跟踪,显示每次迭代中 low、mid、high 的值。
10. Sorting: Bubble Sort | 排序:冒泡排序
Bubble sort is the most frequently examined sorting algorithm in WJEC. It repeatedly steps through the array, compares adjacent elements and swaps them if they are in the wrong order. Each pass places the next largest element in its correct position.
冒泡排序是 WJEC 中最常考的排序算法。它反复遍历数组,比较相邻元素,若顺序错误则交换它们。每一趟将下一个最大元素放到正确位置。
The basic pseudocode with an optimisation flag is:
带优化标志的基本伪代码为:
FOR i ← 0 TO n−2
swapped ← FALSE
FOR j ← 0 TO n−2−i
IF arr[j] > arr[j+1] THEN
SWAP arr[j], arr[j+1]
swapped ← TRUE
ENDIF
ENDFOR
IF swapped = FALSE THEN BREAK
ENDFOR
WJEC mark schemes reward the correct use of a swapped flag to recognise when the array has become sorted early, preventing redundant passes.
WJEC 评分方案奖励正确使用 swapped 标志以识别数组何时已提前排好序,从而避免多余的趟数。
Time complexity is O(n²) in the worst and average cases. Bubble sort is generally inefficient for large datasets but is conceptually simple.
最坏和平均情况下的时间复杂度为 O(n²)。冒泡排序对大数据集通常效率低下,但概念简单。
11. Arrays as Parameters | 数组作为参数传递
In WJEC pseudocode and most high-level languages, arrays are passed to subprograms by reference, meaning changes made to the array inside the procedure affect the original array. This is important for modular program design.
在 WJEC 伪代码和大多数高级语言中,数组通过引用传递给子程序,这意味着在过程内部对数组所做的更改会影响原始数组。这对模块化程序设计很重要。
A procedure header might look like: PROCEDURE SortData(BYREF arr[] OF INTEGER). The BYREF keyword clarifies the passing mechanism, though it is sometimes optional in pseudocode.
过程头可能类似于:PROCEDURE SortData(BYREF arr[] OF INTEGER)。BYREF 关键字阐明了传递机制,尽管它在伪代码中有时是可选的。
You must be able to write subprograms that accept arrays, perform operations such as reversal or filtering, and return either a modified array or a scalar result. WJEC expects clean interface design with parameters rather than reliance on global variables.
你必须能够编写接受数组的子程序,执行反转或过滤等操作,并返回修改后的数组或标量结果。WJEC 期望干净的接口设计,使用参数而非依赖全局变量。
12. Static vs Dynamic Arrays | 静态数组 vs 动态数组
Static arrays have a fixed size determined at compile time. Memory is allocated on the stack. They are fast and predictable but lack flexibility, as you cannot resize them during execution. This is the traditional array model tested in WJEC pseudocode algorithms.
静态数组具有在编译时确定的固定大小。内存分配在栈上。它们快速且可预测,但缺乏灵活性,因为你无法在执行期间调整其大小。这是 WJEC 伪代码算法中考查的传统数组模型。
Dynamic arrays (e.g. Python lists, VB.NET List
动态数组(如 Python 列表、VB.NET 的 List
Understanding the difference is crucial when choosing the appropriate data structure for a given problem, a key skill assessed in both the written paper and the programming project.
在为特定问题选择适当的数据结构时,理解这一区别至关重要,这是笔试和编程项目中都评估的关键技能。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导