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

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

2026-07-13 15:22 · 本文部分内容由AI辅助创作

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

Arrays are one of the fundamental data structures you must master for the IGCSE OCR Computer Science exam. They allow you to store multiple values of the same data type in a single variable, accessed by an index. Understanding how to declare, traverse, search, and sort arrays is essential for writing efficient algorithms and securing top marks in paper-based programming tasks.

数组是 IGCSE OCR 计算机科学考试中必须掌握的核心数据结构之一。它让你能在一个变量中存储多个相同数据类型的值,并通过索引进行访问。理解如何声明、遍历、搜索和排序数组,对于编写高效算法和在试卷中的编程题拿高分至关重要。


1. Introduction to Arrays | 数组简介

An array is a collection of elements, all of the same data type, stored under one identifier. Each element can be accessed individually using its position number, known as the index. In OCR pseudocode, arrays are typically indexed starting from 0, meaning the first element is at position 0, the second at position 1, and so on.

数组是一组相同数据类型的元素,使用一个标识符进行存储。每个元素可以通过其位置编号(索引)单独访问。在 OCR 伪代码中,数组通常从 0 开始索引,即第一个元素位于位置 0,第二个位于位置 1,以此类推。

Arrays provide a way to manage large amounts of related data without declaring numerous separate variables. For example, storing the scores of 100 students is far more practical with a single array than with 100 individual variables.

数组提供了一种无需声明大量独立变量即可管理大量相关数据的方法。例如,用单个数组存储 100 名学生的成绩远比使用 100 个独立变量实用得多。

In IGCSE OCR, you will work mainly with one-dimensional and two-dimensional arrays. Both are static, meaning their size must be defined at the point of declaration and cannot change during program execution.

在 IGCSE OCR 中,你将主要使用一维和二维数组。这两者都是静态的,意味着其大小必须在声明时定义,且在程序执行期间不能改变。


2. Declaring and Indexing Arrays | 数组的声明与索引

In OCR pseudocode, you declare an array by specifying its name and size in square brackets. For instance, ARRAY scores[5] creates an array called scores that can hold 5 integer or real values. If you need to initialise values, you can do so directly: ARRAY names[3] = 'Alex', 'Bella', 'Chris'.

在 OCR 伪代码中,通过指定数组名称和方括号中的大小来声明数组。例如,ARRAY scores[5] 会创建一个名为 scores 的数组,可容纳 5 个整数或实数。如果需要初始化值,可以直接赋值:ARRAY names[3] = 'Alex', 'Bella', 'Chris'。

Indexing is the process of referring to a particular element. The index is always an integer. Because indexing starts at 0, the valid indices for an array of size N are from 0 to N-1. Forgetting this leads to off-by-one errors, which are a common exam pitfall.

索引是指引用特定元素的过程。索引始终是一个整数。由于索引从 0 开始,大小为 N 的数组的有效索引范围为 0 到 N-1。忘记这一点会导致“差一错误”,这是考试中常见的陷阱。

You assign or read a value using the array name followed by the index in square brackets: scores[0] ← 85. This stores 85 in the first position.

你使用数组名称后跟方括号中的索引来赋值或读取值:scores[0] ← 85。这会将 85 存储到第一个位置。


3. One-Dimensional Arrays | 一维数组

A one-dimensional array is often visualised as a single row or list of values. It is the simplest form and is used to store a sequence of items such as daily temperatures, student marks, or a list of product codes.

一维数组通常可视化为一行或一组值的列表。它是最简单的形式,用于存储一系列项目,如每日温度、学生成绩或产品代码列表。

When processing a 1D array, you need to know how many elements it holds. The OCR pseudocode often uses LEN(arr) to return the number of elements. This length is fixed after declaration. A typical loop to display all elements would look like: FOR i ← 0 TO LEN(arr)-1.

在处理一维数组时,你需要知道它包含多少元素。OCR 伪代码通常使用 LEN(arr) 返回元素的数量。此长度在声明后是固定的。显示所有元素的典型循环如下:FOR i ← 0 TO LEN(arr)-1。

Remember that if you attempt to access an index outside the range, such as scores[5] in a 5-element array, a runtime error will occur. Exam questions often test your ability to spot such index-out-of-bounds errors.

请记住,如果试图访问范围外的索引,例如在 5 元素数组中访问 scores[5],就会发生运行时错误。考试题常常会测试你发现这种数组越界错误的能力。


4. Two-Dimensional Arrays | 二维数组

A 2D array can be thought of as a table with rows and columns. In OCR pseudocode, you declare it with two size values, such as ARRAY grid[3][4], which creates 3 rows and 4 columns. The first index refers to the row, the second to the column, both starting at 0.

二维数组可被视为一个由行和列组成的表格。在 OCR 伪代码中,用两个大小值来声明,如 ARRAY grid[3][4] 会创建 3 行 4 列。第一个索引指行,第二个指列,两者均从 0 开始。

To access an element in row r and column c, you write grid[r][c]. For nested traversal, you will use two loops: an outer loop for rows and an inner loop for columns. This is highly examinable.

要访问第 r 行第 c 列的元素,写成 grid[r][c]。进行嵌套遍历时,你要使用两个循环:外循环控制行,内循环控制列。这是考试高频考点。

A common mistake is mixing up rows and columns, or forgetting that both dimensions are zero-indexed. When given a table in an exam question, annotate the row and column indices to avoid confusion.

一个常见错误是混淆行和列,或忘记两个维度都是从零开始索引。当试卷中给出表格时,标出行和列的索引以避免混淆。


5. Iterating Through Arrays with Loops | 使用循环遍历数组

Loops are essential for processing arrays efficiently. OCR expects you to be fluent with both FOR...NEXT loops (count-controlled) and WHILE...ENDWHILE loops for array traversal.

循环对于高效处理数组至关重要。OCR 要求你能熟练使用 FOR...NEXT 循环(计数控制)和 WHILE...ENDWHILE 循环来遍历数组。

For a 1D array, the standard pattern is: FOR index ← 0 TO LEN(myArray)-1. Each iteration handles myArray[index]. This is the building block for summing, finding extremes, and searching.

对于一维数组,标准模式是:FOR index ← 0 TO LEN(myArray)-1。每次迭代处理 myArray[index]。这是求和、查找最值和搜索的基础模块。

When using a WHILE loop, you must manually increment the index and ensure the condition prevents an infinite loop. Compare: i ← 0, then WHILE i < LEN(arr), and inside i ← i + 1.

当使用 WHILE 循环时,必须手动递增索引并确保条件能防止无限循环。对比:i ← 0,然后 WHILE i < LEN(arr),循环体内 i ← i + 1。

For 2D arrays, a nested FOR loop is most common. The outer loop runs for each row, and the inner loop runs for each column within that row. This structure appears in matrix operations and image representation tasks.

对于二维数组,最常用的是嵌套 FOR 循环。外层循环遍历每一行,内层循环遍历该行中的每一列。这种结构出现在矩阵运算和图像表示任务中。


6. Basic Operations – Sum and Average | 基本操作——求和与平均值

Two of the simplest yet most frequently examined operations are calculating the total sum and the average of array elements. The algorithm uses an accumulator variable initialised to zero, which is updated as you iterate.

两项最简单但最常考的操作是计算数组元素的总和以及平均值。算法使用一个初始化为零的累加器变量,随着遍历不断更新它。

In pseudocode: total ← 0, then FOR i ← 0 TO LEN(arr)-1 and inside the loop total ← total + arr[i]. After the loop, the average is total / LEN(arr). Division gives a real result, so your variable should be capable of holding a decimal value.

伪代码中:total ← 0,然后 FOR i ← 0 TO LEN(arr)-1,循环体内 total ← total + arr[i]。循环结束后,平均值是 total / LEN(arr)。除法产生实数结果,因此应使用能存储小数的变量。

Be mindful of integer division if your language specification assumes it. OCR pseudocode does not enforce strict typing, but you should show the average as a real number in trace tables. Practice questions often ask you to complete a trace table for this algorithm.

如果所使用的语言规范假定是整数除法,请格外小心。OCR 伪代码不强制严格类型,但在跟踪表中应显示平均值为实数。练习题经常要求你补全该算法的跟踪表。


广告 / Sponsored

7. Finding Minimum and Maximum Values | 查找最小值和最大值

To find the smallest or largest value in an array, you initialise a candidate variable with the first element (at index 0), then compare it with every other element. If a smaller (or larger) value is found, you update the candidate.

要找到数组中的最小值或最大值,可先用第一个元素(索引 0)初始化一个候选变量,然后将其与其他每个元素进行比较。如果发现更小(或更大)的值,就更新候选变量。

Pseudocode for finding the minimum: min ← arr[0], then FOR i ← 1 TO LEN(arr)-1 and inside check IF arr[i] < min THEN min ← arr[i]. For maximum, simply change the comparison to '>'. This pattern is reliable and efficient.

查找最小值的伪代码:min ← arr[0],然后 FOR i ← 1 TO LEN(arr)-1,循环内判断 IF arr[i] < min THEN min ← arr[i]。对于最大值,只需将比较改为 '>'。这种模式可靠且高效。

Never assume the array is sorted; the algorithm must check every element. Always initialise with an element from the array, not an arbitrary number like 0 or -999, as that could give an incorrect result if all elements are larger or smaller.

绝不要假设数组已排序;算法必须检查每个元素。始终用数组中的元素初始化,而不是像 0 或 -999 这样的任意数字,否则当所有元素都更大或更小时会导致错误结果。


8. Linear Search Algorithm | 线性搜索算法

Linear search is the only search algorithm required for IGCSE OCR. It works by examining each element in order until the target value is found or the end of the array is reached. It is simple but can be slow on very large arrays, though efficiency is not a primary concern at this level.

线性搜索是 IGCSE OCR 要求掌握的唯一搜索算法。它通过按顺序检查每个元素来工作,直到找到目标值或到达数组末尾。它很简单,但在非常大的数组上可能较慢,不过在这个级别效率并非主要关注点。

A standard linear search uses a WHILE or FOR loop. With a WHILE loop, you set found ← FALSE and index ← 0, then loop while not found and index within bounds. Inside, if a match occurs, set found to TRUE; otherwise increment index. A FOR loop with a condition inside can also break early.

标准的线性搜索使用 WHILE 或 FOR 循环。使用 WHILE 循环时,设置 found ← FALSE 和 index ← 0,然后在未找到且索引有效的条件下循环。循环内若匹配,将 found 置为 TRUE;否则递增 index。内部包含条件的 FOR 循环也可提前跳出。

Exam questions may ask you to output the position where the item was found, or to count occurrences. Always remember to handle the situation where the item is not present; often a variable like 'found' keeps track. The algorithm can be presented in a trace table.

考试题可能要求你输出找到项目的位置,或统计出现次数。务必记住处理项目不存在的情况;通常用一个类似 'found' 的变量跟踪。该算法可在跟踪表中呈现。


9. Bubble Sort Algorithm | 冒泡排序算法

Bubble sort is a simple sorting algorithm that repeatedly steps through the array, compares adjacent elements, and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, meaning the array is sorted.

冒泡排序是一种简单的排序算法,它反复遍历数组,比较相邻元素,若它们顺序错误就将它们交换。这一趟趟遍历会一直重复,直至不需要任何交换,即数组已排序。

The pseudocode uses two nested loops. The outer loop controls the number of passes (usually FOR pass ← 0 TO LEN(arr)-2), and the inner loop goes through the unsorted portion. An optimised version uses a swapped flag to exit early if no swaps occur in a pass.

伪代码使用两层嵌套循环。外层循环控制趟数(通常为 FOR pass ← 0 TO LEN(arr)-2),内层循环处理未排序的部分。优化版本使用一个 swapped 标志,若一趟中没有发生任何交换则提前退出。

In a swap, three steps are critical: temp ← arr[j], arr[j] ← arr[j+1], arr[j+1] ← temp. Forgetting the temporary variable is a classic mistake that results in lost data. Trace tables often test your understanding of how values move during swaps.

在交换中,三个步骤至关重要:temp ← arr[j]、arr[j] ← arr[j+1]、arr[j+1] ← temp。忘记使用临时变量是典型错误,会导致数据丢失。跟踪表常常会测试你对交换过程中数值如何移动的理解。

Bubble sort is examined not only as an algorithm to complete but also as a process to analyse: you may be asked how many comparisons or swaps occur on a given array. Know that the worst-case number of comparisons is about n²/2, but exact counts depend on the version.

冒泡排序不仅作为需要完成的算法来考查,也作为一个过程来分析:你可能会被问到在给定数组上发生了多少次比较或交换。要了解最坏情况下的比较次数大约为 n²/2,但具体计数取决于所采用的版本。


10. Common Mistakes and Pitfalls | 常见错误与陷阱

Even strong candidates lose marks due to small array-handling errors. The most frequent mistake is using an incorrect index range (e.g., using 1 to N instead of 0 to N-1). Always write down the array size and first/last indices before coding a solution.

即使实力强的考生也会因小的数组处理错误而丢分。最频繁的错误是使用了错误的索引范围(例如,使用 1 到 N 而不是 0 到 N-1)。在编写解决方案前,应始终写下数组大小以及第一个和最后一个索引。

Another pitfall is attempting to access elements without checking that the index is valid. In linear search, if the search item is not found, the index may go out of bounds if the loop condition is not carefully structured. This is especially critical in WHILE loops.

另一个陷阱是未检查索引是否有效就试图访问元素。在线性搜索中,如果未找到搜索项而循环条件设计不仔细,索引可能会越界。这在 WHILE 循环中尤为关键。

For 2D arrays, transposing rows and columns is a common error. If a table has 5 columns and 3 rows, the array must be declared with row dimension first: [3][5]. Accessing it as [column][row] will either be wrong or out of bounds. Label your variables 'r' and 'c' for clarity.

对于二维数组,转置行和列是常见错误。如果一个表格有 5 列 3 行,数组必须以行维在先声明:[3][5]。以 [column][row] 的方式访问要么是错误的,要么会越界。为清晰起见,可将变量标记为 'r' 和 'c'。

Forgetting to reinitialise accumulators or flag variables between algorithms is also penalised. If you first sum an array and then search for a maximum, ensure that total is reset. Practise writing clear pseudo-code with proper initialisation.

在不同算法之间忘记重新初始化累加器或标志变量也会被扣分。如果你先对数组求和,然后搜索最大值,应确保 total 被重置。练习编写清晰且带有恰当初始化的伪代码。


11. Exam Tips and Practice Questions | 考试技巧与练习题

When tackling array questions in the IGCSE OCR exam, always read the question carefully to identify the array name, size, and initial values if given. Write these down on the question paper. For trace table questions, draw a table with columns for each variable and the loop counter, and row-by-row simulate the code.

应对 IGCSE OCR 考试中的数组问题时,要仔细读题,确定数组名称、大小以及给出的初始值。把这些写在试卷上。对于跟踪表题,画一个表格,为每个变量和循环计数器设置列,然后逐行模拟代码。

If asked to write an algorithm, structure your answer with proper indentation and clear comments. OCR favours structured pseudocode. It need not be perfect in syntax, but logic must be correct. Common tasks: write an algorithm to output all values greater than 50, or to reverse the array contents.

如果要求编写算法,要以恰当的缩进和清晰注释来组织答案。OCR 看重结构化的伪代码。语法无需完美,但逻辑必须正确。常见任务:编写算法输出所有大于 50 的值,或反转数组内容。

Practise past paper questions that involve both 1D and 2D arrays. For example: 'A 1D array temperatures stores the daily temperature for a week. Write an algorithm to find and output the highest temperature.' Also, 'A 2D array chessboard[8][8] stores pieces. Write an algorithm to count the number of white pieces on the board.'

练习涉及一维和二维数组的历年真题。例如:“一个一维数组 temperatures 存储了一周的每日温度。编写算法找出并输出最高温度。”还有,“一个二维数组 chessboard[8][8] 存储棋子。编写算法统计棋盘上白子的数量。”

Time management is key. Array trace questions are worth many marks but can be time-consuming. If stuck, move on and return later. Underline key words: 'output', 'store', 'declare', 'initialise'. These direct the style of your answer.

时间管理是关键。数组跟踪题分值高但可能耗时。如果卡住了,先做后面的再回头。划出关键词:“输出”、“存储”、“声明”、“初始化”。这些词会指导你答案的样式。


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

广告 / Sponsored
现货 Cambridge International AS & ALevel IT Coursebook剑桥国际IGC…
计算机 备考教辅 · 正版现货 · 与本文内容相关
查看详情 / View on Taobao参考价 ¥467.0

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

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