IGCSE WJEC Computer Science: Arrays Revision Notes | IGCSE WJEC 计算机:数组 考点精讲

📚 IGCSE WJEC Computer Science: Arrays Revision Notes | IGCSE WJEC 计算机:数组 考点精讲

Arrays are one of the fundamental data structures in IGCSE WJEC Computer Science. They allow a programmer to store multiple values of the same data type under a single identifier, making it easier to organise and process large amounts of related data. Understanding how to declare, initialise, traverse and manipulate arrays is essential for success in both the theory and practical components of the examination. This revision guide breaks down every key concept, from one‑dimensional arrays to two‑dimensional structures, common algorithms, and typical exam pitfalls.

数组是 IGCSE WJEC 计算机科学中最基础的数据结构之一。它让程序员可以用一个标识符存储多个相同数据类型的值,从而更容易组织和处理大量相关数据。理解如何声明、初始化、遍历和操作数组,对于在考试的理论和实践部分取得成功至关重要。这份复习指南逐一拆解了每一个关键概念,从一维数组到二维结构、常见算法,以及典型的考试易错点。


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

An array is a collection of elements, all of the same data type, stored in contiguous memory locations. Each element can be accessed directly using its index (position). Instead of creating separate variables for a list of exam marks, for example, a single array can hold all the marks under one name, such as marks[0], marks[1], and so on. This makes code shorter, easier to read, and far more efficient when processing data in a loop.

数组是一个由相同数据类型的元素组成的集合,这些元素存储在连续的内存位置中。每个元素都可以通过其索引(位置)直接访问。例如,对于一系列考试成绩,不必为每个成绩创建单独的变量,而是可以用一个数组将所有成绩保存在一个名字下,例如 marks[0]marks[1] 等。这样能让代码更短、更易读,并且在循环中处理数据时效率也更高。

In the WJEC specification, you will often see arrays used to represent lists of numbers, characters, or strings. Arrays are static in size, meaning once declared, their length cannot change during program execution. This is a key difference from dynamic data structures that you may encounter at more advanced levels.

在 WJEC 课程大纲中,你经常会看到数组被用来表示数字、字符或字符串的列表。数组的大小是静态的,也就是说,一旦声明,其长度在程序执行期间就不能再改变。这是它与更高级别中可能遇到的动态数据结构的一个关键区别。


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

Before an array can be used, it must be declared with a name, a data type, and a fixed size. For example, in pseudocode used in WJEC examinations, you might see: DECLARE scores : ARRAY[1..5] OF INTEGER. This creates an array called scores that can hold five integer values, with indices from 1 to 5. In Python‑style pseudocode, you might see: scores = [0, 0, 0, 0, 0] which initialises all elements to zero.

在使用数组之前,必须先声明它的名称、数据类型和固定大小。例如,在 WJEC 考试中使用的伪代码里,你可能会看到:DECLARE scores : ARRAY[1..5] OF INTEGER。这会创建一个名为 scores 的数组,可以存放 5 个整数值,索引从 1 到 5。在类似 Python 的伪代码中,你可能会看到:scores = [0, 0, 0, 0, 0],它将所有元素初始化为 0。

It is important to remember that different programming languages may start indexing at 0 or 1. WJEC pseudocode often uses 1‑based indexing (starting at 1), but the concepts of zero‑based indexing are also tested, so always read the question carefully. Initialisation means giving each element a starting value, which prevents unpredictable behaviour when the program runs.

必须记住,不同的编程语言可能从 0 或 1 开始索引。WJEC 伪代码通常使用基于 1 的索引(从 1 开始),但基于 0 的索引概念也会考查,因此务必仔细审题。初始化就是给每个元素赋一个初始值,这可以防止程序运行时出现不可预测的行为。


3. Array Indexing and Bounds | 数组索引与边界

Every element in an array is identified by a unique index. In the WJEC pseudocode declaration ARRAY[1..n], the valid indices run from 1 to n. Trying to access an index below 1 or above n results in an ‘index out of bounds’ error. This is one of the most frequent runtime errors students encounter, especially when loop counters are not controlled correctly.

数组中的每个元素都由一个唯一的索引来标识。在 WJEC 伪代码声明 ARRAY[1..n] 中,有效的索引范围是 1 到 n。尝试访问小于 1 或大于 n 的索引会导致“索引越界”错误。这是学生最常遇到的运行时错误之一,特别是在循环计数器控制不当的时候。

Consider a 0‑based array with 10 elements: valid indices are 0 to 9. A common mistake is to write a loop that goes from 0 to 10, which would try to access a non‑existent eleventh element. Always ensure that your loop conditions match the declared size of the array, whether you are working with FOR i ← 1 TO LENGTH(arr) or FOR i ← 0 TO LENGTH(arr)-1.

考虑一个有 10 个元素的基于 0 的数组:有效索引为 0 到 9。一个常见的错误是编写从 0 到 10 的循环,这样会试图访问一个不存在的第 11 个元素。无论你使用的是 FOR i ← 1 TO LENGTH(arr) 还是 FOR i ← 0 TO LENGTH(arr)-1,都要确保循环条件与数组声明的大小相匹配。


4. One‑Dimensional Array Operations | 一维数组的操作

The basic operations on a one‑dimensional array include reading data into the array, printing all elements, searching for a value, and finding the sum or average. Because elements are accessed by index, these tasks are almost always performed using a FOR loop. For example, to input five temperatures, the pseudocode would be: FOR i ← 1 TO 5 followed by INPUT temp[i].

对一维数组的基本操作包括将数据读入数组、打印所有元素、搜索某个值以及计算总和或平均值。由于元素通过索引访问,这些任务几乎总是使用 FOR 循环来完成。例如,要输入五个温度,伪代码可以是:FOR i ← 1 TO 5,然后执行 INPUT temp[i]

Another essential operation is linear search, where you iterate through each element to find a match. The algorithm stops when the target is found or the end of the array is reached. Although WJEC does not always require you to write the most efficient algorithm, understanding linear search is vital because it reinforces the concept of sequential access and index management.

另一项基本操作是线性搜索,即遍历每个元素以找到匹配项。当找到目标或到达数组末尾时,算法停止。虽然 WJEC 并不总是要求你编写最高效的算法,但理解线性搜索至关重要,因为它强化了顺序访问和索引管理的概念。


5. Using Loops to Traverse Arrays | 使用循环遍历数组

Traversal means visiting every element of an array exactly once. This is almost always achieved with a counted loop (FOR loop), as the number of elements is known in advance. In WJEC pseudocode, you will typically see: FOR index ← 1 TO LEN(array) or FOR EACH element IN array. The latter is a more modern approach that abstracts away the index, but you must still understand both forms.

遍历意味着恰好访问数组的每个元素一次。这几乎总是通过计数循环(FOR 循环)来实现,因为元素的数量是事先已知的。在 WJEC 伪代码中,你通常会看到:FOR index ← 1 TO LEN(array)FOR EACH element IN array。后者是一种更现代的方法,它将索引抽象化,但你仍然需要理解这两种形式。

When modifying array values during traversal, an index‑based loop is needed because you must specify which element to change. A FOR EACH loop only provides a copy of the value, so changes made inside the loop would not affect the original array unless the language specifically supports it. For WJEC, stick to indexed loops when updating array contents.

当在遍历过程中需要修改数组值时,必须使用基于索引的循环,因为你需要指定要更改的元素。 FOR EACH 循环只提供值的副本,因此除非语言专门支持,否则在循环内部所做的更改不会影响原始数组。在 WJEC 中,更新数组内容时应坚持使用带索引的循环。


6. Two‑Dimensional Arrays | 二维数组

A two‑dimensional (2D) array can be thought of as a table with rows and columns. It is declared with two dimensions, for example: DECLARE grid : ARRAY[1..3, 1..4] OF INTEGER creates a table of 3 rows and 4 columns. Each element is accessed using two indices: grid[2, 3] refers to the value in the second row and third column.

二维数组可以看作是一个由行和列组成的表格。它通过两个维度来声明,例如:DECLARE grid : ARRAY[1..3, 1..4] OF INTEGER 创建了一个 3 行 4 列的表格。每个元素都使用两个索引来访问:grid[2, 3] 指向第二行第三列的值。

Traversing a 2D array typically requires nested loops: an outer loop for rows and an inner loop for columns. In WJEC pseudocode, this would look like: FOR row ← 1 TO 3 and inside that FOR col ← 1 TO 4. This pattern is crucial for tasks such as initialising a board game, processing pixel data, or storing class marks for multiple subjects.

遍历二维数组通常需要嵌套循环:外层循环处理行,内层循环处理列。在 WJEC 伪代码中,这看起来会是这样:FOR row ← 1 TO 3,并在其内部使用 FOR col ← 1 TO 4。这种模式对于初始化棋盘游戏、处理像素数据或存储多个科目的课堂成绩等任务至关重要。


7. Common Algorithms Using Arrays | 使用数组的常见算法

Several standard algorithms appear repeatedly in WJEC examination questions. These include finding the maximum and minimum values, calculating a total and average, counting occurrences of a specific value, and performing a linear search. For a maximum, you initialise a variable with the first element and then compare every other element against it, updating when a larger value is found.

在 WJEC 考试题目中,有几个标准算法会反复出现。其中包括查找最大值和最小值、计算总和与平均值、统计特定值出现的次数以及执行线性搜索。对于最大值,你用一个变量初始化为第一个元素,然后将每个其他元素与其进行比较,当找到更大的值时进行更新。

Another common task is reversing the contents of an array. This can be done by swapping the first element with the last, the second with the second‑last, and so on, until the middle is reached. Pseudocode often uses a temporary variable and a loop that runs up to the halfway point. Understanding these algorithms without having to look them up is a sign of solid preparation.

另一项常见任务是反转数组的内容。这可以通过将第一个元素与最后一个元素交换、第二个与倒数第二个交换,以此类推,直到到达中间位置来实现。伪代码通常使用一个临时变量和一个循环,循环一直运行到一半的位置。能够在无需查阅的情况下理解这些算法,是扎实备考的标志。


8. Writing Robust Array Code | 编写健壮的数组代码

Robustness means your code can handle unexpected inputs without crashing. With arrays, this mostly involves validating user input to ensure it falls within the allowed index range before attempting to access an element. For example, if a program asks the user to enter a day number (1–7) to retrieve a weekday from an array, the program should check IF day >= 1 AND day <= 7 before using it as an index.

健壮性意味着你的代码可以处理意外的输入而不会崩溃。对于数组来说,这主要涉及在尝试访问元素之前,要验证用户输入以确保它在允许的索引范围内。例如,如果一个程序要求用户输入一个天数(1–7)来从数组中获取星期几,那么程序应该在使用该输入作为索引之前检查 IF day >= 1 AND day <= 7

Additionally, always consider the possibility of an empty array (size zero) if your language or pseudocode allows it. Attempting to access the first element of an empty array would cause an error. In WJEC, arrays usually have a declared size greater than zero, but writing a condition to check IF LEN(array) > 0 shows advanced awareness.

此外,如果你的语言或伪代码允许空数组(大小为零),要始终考虑它的可能性。尝试访问空数组的第一个元素会导致错误。在 WJEC 中,数组通常声明的大小大于零,但编写一个条件来检查 IF LEN(array) > 0 能体现出更高阶的意识。


9. Arrays in Real‑World Contexts | 数组在真实世界场景中的应用

WJEC often frames array questions within realistic scenarios: storing the names of players in a game, recording temperatures over a week, or holding the high scores of a quiz. This tests your ability to map a problem onto an appropriate data structure. For example, a program that tracks stock levels for 50 products would naturally use an array of 50 integers, where each position corresponds to a product ID.

WJEC 经常将数组问题置于现实场景中:存储游戏中的玩家姓名、记录一周内的温度,或者保存测验的最高分。这会考查你将问题映射到合适数据结构上的能力。例如,一个跟踪 50 种产品库存水平的程序,自然就会使用一个包含 50 个整数的数组,其中每个位置对应一个产品 ID。

Another typical scenario is a simple encryption task where each letter in a message is shifted using a parallel array, or a voting system where candidate names are held in one array and their vote counts in another, with the same index linking them. Being able to describe and justify your choice of an array is a skill that marks out top‑level answers.

另一个典型场景是一个简单的加密任务,其中消息中的每个字母都使用一个并行数组进行移位;或者一个投票系统,候选人姓名保存在一个数组中,他们的得票数保存在另一个数组中,通过相同的索引将它们关联起来。能够描述并证明你选择数组的合理性,是高水平答案的标志性技能。


10. Common Mistakes and How to Avoid Them | 常见错误及避免方法

One of the biggest pitfalls is the off‑by‑one error. Students often confuse the size of an array with the highest index. If an array has size 10 and is 0‑based, the indices are 0–9, not 1–10. Writing a loop from 0 to 10 will attempt to access an eleventh element. Always double‑check your loop boundaries using the formula: valid indices = 0 to size‑1 (for 0‑based arrays).

最大的陷阱之一是差一错误(off‑by‑one error)。学生经常把数组的大小和最高索引混淆。如果一个数组的大小为 10 并且是 0 基底的,那么索引是 0–9,而不是 1–10。编写一个从 0 到 10 的循环会试图访问第十一个元素。务必使用公式仔细检查你的循环边界:有效索引 = 0 到 size‑1(针对 0 基底的数组)。

Another frequent mistake is forgetting to initialise array elements before using them. If an array is declared but not filled with data, trying to print or calculate with those elements may give garbage values or cause errors. In pseudocode, always show a step like FOR i ← 1 TO 5 SET arr[i] ← 0 if the question expects a clean starting state. This demonstrates thorough planning.

另一个常见错误是在使用数组元素之前忘记初始化它们。如果声明了数组但未填入数据,尝试打印或使用这些元素进行计算可能会产生垃圾值或导致错误。在伪代码中,如果题目期望一个干净的起始状态,务必展示一个步骤,例如 FOR i ← 1 TO 5 SET arr[i] ← 0。这表明你有周密的规划。


11. Exam Tips for Array Questions | 数组题目的考试技巧

When tackling array questions, read the declared index range very carefully. If the question uses ARRAY[0..4] and you write a loop from 1 to 5, you will lose marks for incorrect indexing. Highlight the lower and upper bounds on your exam paper to stay focused. If the question asks for a trace table, make sure your table includes a column for each array element or clearly shows how the array changes at each step.

在应对数组题目时,要非常仔细地阅读声明的索引范围。如果题目使用 ARRAY[0..4],而你写了一个从 1 到 5 的循环,你就会因为索引不正确而丢分。在试卷上把下界和上界高亮标注出来,以保持专注。如果题目要求编写跟踪表(trace table),确保你的表格为每个数组元素设置一列,或者清晰地展示数组在每一步中是如何变化的。

Also, practise writing algorithms in the WJEC pseudocode style so that you can express your ideas fluently under time pressure. Many marks are awarded for correct syntax details, such as using the correct assignment arrow (←) and proper loop structures. Finally, always leave a couple of minutes to mentally test your array code with a small set of sample data—this often catches logical errors before they cost you marks.

此外,要练习用 WJEC 伪代码风格编写算法,这样你就能在时间压力下流畅地表达你的思路。很多分数会给在正确的语法细节上,比如使用正确的赋值箭头(←)和恰当的循环结构。最后,一定要留出几分钟时间,用一小组样本数据在心里测试你的数组代码——这往往能在逻辑错误导致失分之前将其捕捉到。


12. Summary and Final Review | 总结与最终回顾

Arrays are powerful tools that allow efficient storage and manipulation of collections of data. For the IGCSE WJEC Computer Science examination, you must be confident in declaring arrays, using indices correctly, traversing with loops, and applying standard algorithms to both one‑dimensional and two‑dimensional structures. Robustness, validation, and real‑world application are also key assessment areas.

数组是强大的工具,能够高效地存储和操作数据集合。对于 IGCSE WJEC 计算机科学考试,你必须能自信地声明数组、正确使用索引、用循环进行遍历,并对一维和二维结构应用标准算法。健壮性、验证和实际应用也是关键的评估领域。

Remember that arrays are a foundation for many more advanced topics in computer science. Mastering them now will pay off not only in your exam but also in future studies of lists, databases, and algorithmic thinking. Use this revision guide alongside past paper practise, and you will be well prepared to handle any array question WJEC sets.

请记住,数组是计算机科学中许多更高级主题的基础。现在掌握它们,不仅会在考试中有所回报,也会对将来学习列表、数据库和算法思维大有裨益。将这份复习指南与历年真题练习结合使用,你将做好充分准备,应对 WJEC 设置的任何数组题目。

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