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

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

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

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

Arrays are one of the fundamental data structures in GCSE CIE Computer Science. They allow you to store multiple pieces of data of the same type under a single identifier and access each element using an index. Mastering arrays is essential for solving problems such as sorting, searching, and storing tabular data in pseudocode. This revision guide covers the key concepts you need to know for the exam.

数组是 GCSE CIE 计算机科学中最基本的数据结构之一。它能在单一标识符下存储多个相同类型的数据,并通过索引访问每个元素。掌握数组对于用伪代码解决排序、查找和储存表格数据等问题至关重要。本复习指南涵盖考试需要掌握的核心概念。

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

An array is a collection of elements, each identified by an index or key. All elements in an array must be of the same data type, such as INTEGER or STRING. Arrays have a fixed size, meaning the number of elements is defined when the array is created and cannot easily be changed during program execution.

数组是一组元素的集合,每个元素通过索引或键来标识。数组中所有元素必须是相同的数据类型,例如 INTEGER 或 STRING。数组具有固定大小,即元素数量在创建数组时定义,程序执行期间通常不能随意更改。

For example, a 1D array called 'marks' with 5 elements would store 5 integer values. The first element is at index 0 or 1 depending on the language, but in CIE pseudocode, arrays usually start at index 1 unless otherwise stated.

例如,一个名为 'marks'、包含5个元素的一维数组将存储5个整数值。第一个元素的索引是0还是1取决于语言,但在 CIE 伪代码中,数组通常从索引1开始,除非另有说明。

A typical array declaration in pseudocode: DECLARE marks : ARRAY[1:5] OF INTEGER

典型的伪代码数组声明:DECLARE marks : ARRAY[1:5] OF INTEGER


2. Declaring Arrays in Pseudocode | 用伪代码声明数组

In the CIE pseudocode, you declare a 1D array using the syntax: DECLARE <identifier> : ARRAY[<lower>:<upper>] OF <type>. For 2D arrays, you use: ARRAY[1:rows, 1:columns] OF type. The lower and upper bounds can be any integers; often they start at 1.

在 CIE 伪代码中,一维数组的声明语法为:DECLARE <标识符> : ARRAY[<下限>:<上限>] OF <类型>。二维数组则使用:ARRAY[1:行数, 1:列数] OF 类型。上下限可以是任意整数,通常从1开始。

Examples:

例子:

DECLARE temperatures : ARRAY[1:7] OF REAL
DECLARE chessboard : ARRAY[1:8, 1:8] OF STRING
DECLARE names : ARRAY[1:100] OF STRING

Always remember that in CIE, the array size is fixed at declaration and cannot be changed dynamically. You need to decide the maximum size beforehand.

始终记住,在 CIE 中,数组大小在声明时固定,不能动态改变。你需要提前确定最大大小。


3. Accessing Array Elements | 访问数组元素

You access an element by specifying the array name followed by the index in square brackets. For example, marks[3] refers to the third element in the array 'marks'. Assignments work the same way: marks[3] ← 95 stores the value 95 at index 3.

访问元素需要指定数组名和写在方括号中的索引。例如,marks[3] 表示数组 'marks' 中的第三个元素。赋值方式相同:marks[3] ← 95 将值95存入索引3的位置。

In 2D arrays, you use two indices: grid[row, column]. For instance, grid[2,3] accesses the element at the second row and third column.

在二维数组中,需要使用两个索引:grid[行, 列]。例如,grid[2,3] 访问第二行第三列的元素。

Common mistake: attempting to access an index outside the declared bounds (e.g., marks[0] when the array was declared as ARRAY[1:5]) will cause an error. Always ensure your index is within the valid range.

常见错误:尝试访问超出声明范围的索引(例如,数组声明为 ARRAY[1:5] 却访问 marks[0])会导致错误。务必确保索引在有效范围内。


4. Iterating Through Arrays | 遍历数组

To process all elements of an array, you typically use a FOR loop with a counter variable that goes from the lower bound to the upper bound. Inside the loop, you use the counter as the index.

要处理数组中的所有元素,通常使用一个 FOR 循环,计数器变量从下限递增到上限。在循环内部,将计数器用作索引。

Example – printing all names:

例子 – 打印所有姓名:

FOR i ← 1 TO 100
    OUTPUT names[i]
NEXT i

For a 2D array, you nest two loops – one for rows and one for columns. This allows you to traverse a table systematically.

对于二维数组,可以嵌套两个循环——一个用于行,一个用于列。这样就能系统地遍历整个表格。

Iteration is fundamental to common algorithms like linear search, counting occurrences, and calculating totals.

遍历是实现线性搜索、计数出现次数和计算总和等常见算法的基础。


5. Array Indexing Rules | 数组索引规则

CIE pseudocode arrays can be declared with any integer bounds. If no bounds are specified, assume the array index starts at 1. The index must be an integer value; you cannot use a real number or a string as an index.

CIE 伪代码数组可以用任何整数边界声明。如果没有指定边界,默认数组索引从1开始。索引必须是整数值;不能使用实数或字符串作为索引。

When using a loop variable as an index, always check the loop range matches the array bounds exactly. For a 0-based array (e.g., ARRAY[0:4]), a loop from 0 to 4 is correct.

当用循环变量作为索引时,务必检查循环范围与数组边界完全匹配。对于从0开始的数组(例如 ARRAY[0:4]),循环从0到4才是正确的。

Some algorithms require reading arrays from an external file. The exam question will specify how many elements to read. Always stop reading when you reach the count or the end-of-file marker.

有些算法要求从外部文件读取数组。题目会指定读取多少个元素。当达到数量或文件结束标记时,务必停止读取。


6. Common Array Operations | 常见数组操作

Beyond storing and retrieving data, arrays are manipulated through standard operations. You will encounter tasks such as: summing all elements, counting elements that meet a condition, finding an average, or reversing the order of elements.

除了存储和检索数据,数组还通过标准操作进行处理。你会遇到像求所有元素之和、统计满足条件的元素个数、求平均值或反转元素顺序等任务。

Operation 操作Pseudocode example 伪代码示例
Sum elements 求和total ← 0
FOR i ← 1 TO 10
total ← total + numbers[i]
NEXT i
Count matches 计数匹配count ← 0
FOR i ← 1 TO 10
IF numbers[i] = target THEN
count ← count + 1
ENDIF
NEXT i
Reverse array 反转数组FOR i ← 1 TO 5
temp ← arr[i]
arr[i] ← arr[11-i]
arr[11-i] ← temp
NEXT i

These operations are frequently examined, so practice writing them out yourself.

这些操作经常考到,所以务必自己动手练习编写。


广告 / Sponsored

7. 1D vs 2D Arrays | 一维数组与二维数组

A 1D array is essentially a single list. A 2D array can be thought of as a table with rows and columns. In CIE pseudocode, you declare a 2D array as ARRAY[1:3, 1:4] OF INTEGER to create a 3 × 4 table.

一维数组本质上就是一个列表。二维数组可以想象成一张有行和列的表格。在 CIE 伪代码中,声明 ARRAY[1:3, 1:4] OF INTEGER 就能创建一个 3 × 4 的表格。

Accessing a 2D array uses two indices: table[row, column]. Remember that row index comes first, then column.

访问二维数组使用两个索引:table[行, 列]。记住行索引在前,列索引在后。

Typical exam question: "Write an algorithm that reads 30 student names and their 5 test scores, storing them in a 2D array." You would declare the array as DECLARE studentData : ARRAY[1:30, 1:6] OF STRING (or perhaps a mixture of types, which is not allowed, so you'd need two separate arrays or use a well-defined structure – CIE pseudocode requires all elements to be the same type, so names and scores would need separate arrays).

典型考题:"编写一个算法,读取30名学生的姓名及其5次测试成绩,并将它们存入二维数组。" 由于 CIE 伪代码要求所有元素类型相同,姓名和成绩需要分开存储,或者题目会明确允许混合类型存储的修改规则,但通常建议分别用两个数组来存储。


8. Using Arrays for Lookup Tables | 使用数组实现查找表

Arrays are excellent for implementing lookup tables where you map an input value to an output value. For example, storing days of the week as strings so that a number (1-7) returns the corresponding day name.

数组非常适合实现查找表,将输入值映射到输出值。例如,将星期几的字符串存储起来,这样数字(1-7)就能返回对应的日期名称。

Example: dayNames : ARRAY[1:7] OF STRING ← ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"] (Actual CIE pseudocode may not support inline initialisation like this; you would assign each element individually or read from a file).

例子:dayNames : ARRAY[1:7] OF STRING ← ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"](实际 CIE 伪代码可能不支持这种内联初始化;你需要逐个赋值或从文件读取)。

Lookup tables are used in many programs, such as a grade boundaries table that maps a score to a letter grade. The key is to ensure the index corresponds to the correct category.

查找表在很多程序中使用,比如将分数映射为字母等级的成绩边界表。关键在于确保索引与正确的类别对应。


9. Array Algorithms: Searching | 数组算法:查找

Linear search is the simplest searching algorithm. It checks each element of the array in order until the target is found or the end is reached. Its time complexity is O(n).

线性搜索是最简单的查找算法。它按顺序检查数组中的每个元素,直到找到目标或到达末尾。其时间复杂度为 O(n)。

Pseudocode for linear search:

线性搜索的伪代码:

FUNCTION linearSearch(arr, target)
    FOR i ← 1 TO LENGTH(arr)
        IF arr[i] = target THEN
            RETURN i
        ENDIF
    NEXT i
    RETURN -1
ENDFUNCTION

In CIE, you often need to output a message like "Found at position" or "Not found". You can use a Boolean flag to remember if the item was found.

在 CIE 中,你常常需要输出类似 "Found at position" 或 "Not found" 的消息。可以使用布尔标志来记录是否找到。

Binary search is only applicable on sorted arrays and is more efficient (O(log n)), but it is more complex to implement. For GCSE, linear search is the main focus.

二分搜索仅适用于已排序的数组,效率更高(O(log n)),但实现更复杂。GCSE 阶段主要考察线性搜索。


10. Array Algorithms: Finding Maximum/Minimum | 数组算法:寻找最大值/最小值

To find the maximum value in an array, initialise a variable to the first element, then compare every other element against it. If a larger element is found, update the maximum.

要找出数组中的最大值,首先用一个变量初始化为第一个元素,然后将其他元素一一与之比较。如果发现更大的元素,就更新最大值。

Pseudocode:

伪代码:

maxVal ← numbers[1]
FOR i ← 2 TO 100
    IF numbers[i] > maxVal THEN
        maxVal ← numbers[i]
    ENDIF
NEXT i
OUTPUT maxVal

For minimum, change the comparison to numbers[i] < minVal. The same logic applies to 2D arrays, but you need nested loops.

寻找最小值时,将比较改为 numbers[i] < minVal。同样的逻辑也适用于二维数组,但需要使用嵌套循环。

This algorithm often appears alongside searching in exam questions.

该算法常与查找一起出现在考题中。


11. Array Algorithms: Sorting (Bubble Sort) | 数组算法:排序(冒泡排序)

Bubble sort is the standard sorting algorithm required for the CIE GCSE syllabus. It repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The pass is repeated until no swaps are needed.

冒泡排序是 CIE GCSE 大纲要求掌握的标准排序算法。它反复遍历列表,比较相邻元素,若顺序错误就交换它们。重复这个过程直到不需要任何交换为止。

Pseudocode for bubble sort in ascending order:

升序冒泡排序的伪代码:

DECLARE swapped : BOOLEAN
REPEAT
    swapped ← FALSE
    FOR i ← 1 TO n-1
        IF arr[i] > arr[i+1] THEN
            temp ← arr[i]
            arr[i] ← arr[i+1]
            arr[i+1] ← temp
            swapped ← TRUE
        ENDIF
    NEXT i
UNTIL swapped = FALSE

Remember that bubble sort is not the most efficient (O(n²)), but it is conceptually simple. You may be asked to trace the algorithm or write the code.

记住冒泡排序并非最高效(O(n²)),但概念简单。你可能需要跟踪算法执行或编写代码。


12. Limitations and Alternatives | 局限性与替代方案

Arrays have a fixed size, which can lead to wasted memory if the maximum is overestimated, or to an error if you try to exceed the declared capacity. They also require all elements to be of the same type.

数组大小固定,若高估最大容量会浪费内存;若超过声明的容量则会导致错误。此外,所有元素必须为同一类型。

In some problems, a more flexible data structure like a list (which can grow dynamically) might be better, but the CIE pseudocode does not have built-in dynamic lists. You must stick with arrays.

在某些问题中,像列表这样可以动态增长的数据结构可能更好,但 CIE 伪代码没有内置的动态列表,所以必须使用数组。

For 2D arrays, the rectangular structure is ideal for tables, but not for jagged data (different row lengths). You may need to use a 1D array of strings or work within the fixed column count.

对于二维数组,矩形结构非常适合表格数据,但不适合锯齿状数据(不同行长度不同)。你可能需要借助字符串的一维数组,或在固定列数范围内处理。

Understanding arrays, their syntax, and common algorithms will set you up for success in the paper. Practise writing pseudocode for the operations covered here, and always double-check index bounds.

理解数组、其语法以及常见算法,能帮助你在考试中取得成功。练习编写本文所涉及操作的伪代码,并始终仔细检查索引边界。

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

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

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

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