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

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

Arrays are one of the most fundamental data structures in programming. For the CCEA GCSE Computer Science specification, you need to understand how to declare, initialise, and manipulate both one-dimensional and two-dimensional arrays, as well as how to apply common algorithms such as linear search and bubble sort. This revision guide breaks down every key point, pairing clear explanations in English with Chinese translations to support bilingual learners.

数组是编程中最基本的数据结构之一。根据 CCEA 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. Instead of using separate variables for related data, an array lets you store them under a single name and access each element using an index.

数组是一种能够存放固定数量元素的数据结构,且所有元素的数据类型均相同。你不必为相关联的数据定义多个单独的变量,而是可以通过一个名字储存它们,并使用索引访问每一个元素。

Elements in an array are stored in contiguous memory locations, which makes accessing any element very fast if you know its index. The index is usually an integer, starting from 0 in most programming languages used in the CCEA course, such as Python (lists can be treated as arrays) or pseudocode.

数组中的元素连续地存储在内存中,因此只要知道索引,访问任何元素都非常快。索引通常是一个整数,在 CCEA 课程常用的语言(如 Python,列表可视为数组)或伪代码中,索引一般从 0 开始。


2. One-Dimensional Arrays | 一维数组

A one-dimensional (1D) array is the simplest form, essentially a list of values. For example, the scores of five students can be stored in an array named scores[5], where scores[0] holds the first value, scores[1] the second, and so on.

一维数组是最简单的形式,它本质上就是一个数值列表。例如,五名学生的分数可以存储在名为 scores[5] 的数组中,其中 scores[0] 存放第一个值,scores[1] 存放第二个,以此类推。

You must be able to declare a 1D array in pseudocode and in your chosen programming language. In pseudocode, this might look like: DECLARE scores : ARRAY[0:4] OF INTEGER. You then assign values using statements such as scores[0] ← 85.

你必须能够在伪代码和你选择的编程语言中声明一维数组。在伪代码中,这可能写作:DECLARE scores : ARRAY[0:4] OF INTEGER。然后通过类似 scores[0] ← 85 的语句赋值。


3. Traversing a One-Dimensional Array | 遍历一维数组

Traversing means accessing each element of the array in order, usually with a loop. A FOR loop is the most common method. For a 1D array of size 5, a loop counter i from 0 to 4 allows you to read or modify every element.

遍历就是按顺序访问数组中的每个元素,通常使用循环来完成。FOR 循环是最常见的方式。对于一个大小为 5 的一维数组,循环变量 i 从 0 到 4 可以让你读取或修改每一个元素。

In pseudocode: FOR i ← 0 TO 4 OUTPUT scores[i] ENDFOR. You can also compute totals: total ← 0 FOR i ← 0 TO 4 total ← total + scores[i] ENDFOR. Traversal underpins many algorithms you will need to write in the exam.

伪代码示例:FOR i ← 0 TO 4 OUTPUT scores[i] ENDFOR。你也可以计算总和:total ← 0 FOR i ← 0 TO 4 total ← total + scores[i] ENDFOR。遍历是考试中许多算法的基础。


4. Two-Dimensional Arrays | 二维数组

A two-dimensional (2D) array can be thought of as a table with rows and columns. You use two indices to locate an element: the first for the row and the second for the column. For instance, a classroom seating plan could be stored in seat[3,4], meaning 3 rows and 4 columns.

二维数组可以看作是一个有行、列的表格。你使用两个索引来定位元素:第一个指定行,第二个指定列。例如,教室座位表可以存储在 seat[3,4] 中,代表 3 行 4 列。

Declaration in pseudocode: DECLARE grid : ARRAY[0:2,0:3] OF STRING. Accessing an element is done with grid[1,2] ← “Alice”. Remember that indices often start at 0, so the first row is 0 and the first column is 0.

伪代码中的声明:DECLARE grid : ARRAY[0:2,0:3] OF STRING。访问元素使用 grid[1,2] ← “Alice”。记住索引通常从 0 开始,因此第一行是 0,第一列也是 0。


5. Traversing a Two-Dimensional Array | 遍历二维数组

To visit every element in a 2D array, you need a nested loop: an outer loop for rows and an inner loop for columns. For an array declared as matrix[0:2,0:3], a typical nested FOR loop looks like: FOR row ← 0 TO 2 FOR col ← 0 TO 3 OUTPUT matrix[row,col] ENDFOR ENDFOR.

要访问二维数组中的每个元素,你需使用嵌套循环:外层循环控制行,内层循环控制列。对于声明为 matrix[0:2,0:3] 的数组,典型的嵌套 FOR 循环如下:FOR row ← 0 TO 2 FOR col ← 0 TO 3 OUTPUT matrix[row,col] ENDFOR ENDFOR

You can also traverse by columns first if the question requires it (column-major order), but GCSE CCEA mainly expects row-major traversal. Be ready to adapt your loop bounds to the declared dimensions.

如果题目要求,你也可以先按列遍历(列主序),但 GCSE CCEA 主要考查行主序遍历。你需要能够根据声明的尺寸灵活调整循环边界。


6. Array Indexing and Boundaries | 数组索引与边界

Array indices in pseudocode and in languages like Python start at 0. The highest valid index is length – 1. For an array of size 5, valid indices are 0, 1, 2, 3, 4. Trying to use index 5 would cause an “index out of bounds” error.

伪代码和 Python 等语言中的数组索引从 0 开始。最大有效索引为 长度 – 1。对于大小为 5 的数组,有效索引是 0、1、2、3、4。尝试使用索引 5 将导致“索引越界”错误。

You are expected to write code that prevents out-of-bounds errors, for example by setting loop limits correctly. When working with user input as an index, validation is essential to ensure the value is within the array’s range.

考试中要求你编写的代码要防止越界错误,例如正确设置循环界限。当使用用户输入的索引时,必须验证该值在数组范围内。


7. Common Algorithm: Linear Search on an Array | 常见算法:数组的线性搜索

Linear search checks each element of an array one by one until it finds the target value or reaches the end. It works on unsorted data and is simple to implement, but it can be slow for large arrays because it examines every element in the worst case.

线性搜索逐个检查数组中的每个元素,直到找到目标值或到达数组末尾。它可以处理未排序的数据,实现简单,但最坏情况下需要检查所有元素,对于大数组来说速度较慢。

In pseudocode, to search for a value target in an array arr of size n: found ← FALSE FOR i ← 0 TO n-1 IF arr[i] = target THEN OUTPUT i found ← TRUE ENDIF ENDFOR IF NOT found THEN OUTPUT “Not found”.

伪代码中,在大小为 n 的数组 arr 中搜索数值 targetfound ← FALSE FOR i ← 0 TO n-1 IF arr[i] = target THEN OUTPUT i found ← TRUE ENDIF ENDFOR IF NOT found THEN OUTPUT “Not found”


8. Common Algorithm: Bubble Sort on a 1D Array | 常见算法:一维数组的冒泡排序

Bubble sort works by repeatedly stepping through the array, comparing adjacent elements and swapping them if they are in the wrong order. After each pass, the next largest element “bubbles” to its correct position. The sort finishes when a pass occurs with no swaps.

冒泡排序通过反复遍历数组,比较相邻元素并在顺序错误时交换它们。每完成一遍遍历,下一个最大元素就会“冒泡”到正确位置。当某遍遍历没有发生交换时,排序结束。

Pseudocode for ascending order: FOR i ← 0 TO n-2 FOR j ← 0 TO n-2-i IF arr[j] > arr[j+1] THEN temp ← arr[j] arr[j] ← arr[j+1] arr[j+1] ← temp ENDIF ENDFOR ENDFOR. Notice the inner loop limit reduces by i since the last i elements are already sorted.

升序排列的伪代码:FOR i ← 0 TO n-2 FOR j ← 0 TO n-2-i IF arr[j] > arr[j+1] THEN temp ← arr[j] arr[j] ← arr[j+1] arr[j+1] ← temp ENDIF ENDFOR ENDFOR。注意内层循环的上限随 i 减小,因为末尾 i 个元素已排好。


9. Storing and Accessing Multi-dimensional Data | 多维数据的存储与访问

GCSE CCEA often uses 2D arrays to model real-world data like game boards (e.g., battleships), timetables, or pixel grids. You may be asked to update a specific cell based on user input, or to count how many cells meet a condition. Always think of the structure as a grid of rows and columns.

GCSE CCEA 常使用二维数组对现实世界的数据建模,如游戏棋盘(例如战舰游戏)、课程表或像素网格。你可能需要根据用户输入更新特定单元格,或统计满足某个条件的单元格数量。始终将这个结构想象为行和列组成的网格。

When writing algorithms, identify which dimension is being scanned: for example, “check every student in class 2” might mean fixing the row index for class 2 and looping through all columns. Use a systematic approach: row first, then column.

编写算法时,要明确正在扫描哪一个维度:例如,“检查 2 班的每位学生”可能意味着将代表 2 班的行索引固定,然后遍历所有列。采用系统化的方式:先行后列。


10. Memory and Efficiency Considerations | 内存与效率注意事项

Arrays use a single contiguous block of memory, which makes access fast but can make insertion or deletion slow if elements need to be shifted. At GCSE, you mainly need to appreciate that the size of an array is fixed at declaration and cannot be changed dynamically in most pseudocode contexts.

数组使用单一连续的内存块,这让访问速度很快,但如果需要移动元素,插入或删除就会很慢。在 GCSE 阶段,你主要需要理解数组的大小在声明时就已经固定,在大多数伪代码情景中不能动态改变。

For searching and sorting, you should be aware that linear search has a worst-case time proportional to the array size (n), while bubble sort has a worst-case time proportional to n². These ideas help you compare algorithms but you do not need formal Big O notation.

对于搜索和排序,你应该知道线性搜索的最坏情况时间与数组大小 n 成正比,而冒泡排序的最坏情况时间与 n² 成正比。这些概念帮助你比较算法,但不需要正式的“大 O 表示法”。


11. Exam-Style Tips for Array Questions | 考试风格题目提示

Read the question carefully to see whether array indices start at 0 or 1. CCEA pseudocode often uses 0-based indexing, but occasionally a question might define an array from 1 to N – follow the question’s lead. Always trace your algorithm with a small example to check boundary conditions.

仔细阅读题目,看清楚数组索引是从 0 还是 1 开始。CCEA 伪代码通常使用基于 0 的索引,但偶尔题目可能定义一个从 1 到 N 的数组——请以题目为准。始终用一个小的例子跟踪你的算法,检查边界条件。

When writing sorting or searching code, label your loops clearly and use meaningful variable names. If you are asked to complete or correct an algorithm, check for off-by-one errors and ensure swapping uses a temporary variable correctly.

在编写排序或搜索代码时,清晰地标注你的循环,并使用有意义的变量名。如果题目要求补全或修正算法,检查是否存在“差一错误”,并确保交换操作正确使用了临时变量。


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课程辅导,国外大学本科硕士研究生博士课程论文辅导

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