IB Computer Science: Arrays Exam Focus | IB 计算机:数组 考点精讲

📚 IB Computer Science: Arrays Exam Focus | IB 计算机:数组 考点精讲

Arrays form the backbone of data storage in programming and are a guaranteed topic in IB Computer Science examinations, spanning both Standard Level (SL) and Higher Level (HL) papers. From Paper 1 tracing exercises to Paper 2 algorithmic solutions, understanding array declaration, traversal, searching, and sorting is essential. This guide breaks down each key concept with paired explanations and practical examples to help you master arrays for mock exams and the final assessment.

数组是编程中数据存储的基础,也是 IB 计算机科学考试中必考的内容,涵盖标准级别 (SL) 与高级别 (HL) 试卷。从 Paper 1 的追踪题到 Paper 2 的算法设计题,理解数组的声明、遍历、查找和排序至关重要。本指南将逐一拆解每个关键概念,配以中英双语解释和实用示例,帮助你掌握数组,备战模拟考和最终评估。

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

An array is a collection of variables, all of the same data type, stored in contiguous memory locations. Each element is accessed using an index (or subscript). Arrays provide a structured way to manage multiple data items without declaring separate variables. In IB pseudocode, arrays can be one-dimensional (1D) or two-dimensional (2D), and they often represent lists, tables, or matrices.

数组是存储在连续内存位置中的一组同一数据类型的变量集合。每个元素通过索引(下标)访问。数组提供了一种结构化的方式来管理多个数据项,而无需声明单独的变量。在 IB 伪代码中,数组可以是一维 (1D) 或二维 (2D) 的,常用于表示列表、表格或矩阵。

Key point: Arrays are homogeneous – all elements must be of the same type (e.g., all integers or all strings). This distinguishes them from composite structures like records or objects. In Java, an array is an object; in IB’s prescribed pseudocode, arrays are declared with the keyword ARRAY or using bracket notation.

关键点:数组是同质的——所有元素必须是同一类型(例如,全是整数或全是字符串)。这与记录或对象等复合结构有所不同。在 Java 中,数组是对象;在 IB 规定的伪代码中,数组的声明使用关键字 ARRAY 或方括号表示法。


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

Understanding indexing is crucial for array manipulation. Most IB examples use zero-based indexing, where the first element is at index 0. Thus, for an array of size N, valid indices range from 0 to N-1. If a question uses one-based indexing (index starting from 1), it will be explicitly stated. Attempting to access an index outside the valid range results in an “index out of bounds” error, a common runtime exception.

理解索引对数组操作至关重要。大多数 IB 示例使用基于零的索引,即第一个元素在索引 0。因此,对于大小为 N 的数组,有效索引范围是 0 到 N-1。如果题目使用基于一的索引(索引从 1 开始),则会明确说明。尝试访问有效范围外的索引会导致“索引越界”错误,这是一种常见的运行时异常。

In Java: int[] scores = new int[5]; creates indices 0,1,2,3,4. Accessing scores[5] throws ArrayIndexOutOfBoundsException. In IB pseudocode, the length of an array can be obtained by a built-in function like length(arr) or by referencing arr.length (depending on the version). Always guard loops with a condition checking the array length.

在 Java 中:int[] scores = new int[5]; 创建索引 0、1、2、3、4。访问 scores[5] 会抛出 ArrayIndexOutOfBoundsException。在 IB 伪代码中,数组的长度可以通过内置函数如 length(arr) 或引用 arr.length 获得(视版本而定)。始终用条件判断数组长度来保护循环。


3. Declaring and Initializing Arrays | 声明与初始化数组

IB often tests the ability to read and write array declarations. In pseudocode, you might see: DECLARE nums : ARRAY[1:10] OF INTEGER (one-based) or DECLARE names : ARRAY[0:4] OF STRING. Alternatively, a shorthand initialization: values = [2, 4, 6, 8]. Java syntax is equally important: int[] data = new int[100]; or String[] words = {"hello", "world"};. Note that once an array is created, its size cannot be changed (static array in Java).

IB 考试常测试读写数组声明。伪代码中可能看到:DECLARE nums : ARRAY[1:10] OF INTEGER(基于一)或 DECLARE names : ARRAY[0:4] OF STRING。或者简化初始化:values = [2, 4, 6, 8]。Java 语法同样重要:int[] data = new int[100];String[] words = {"hello", "world"};。注意,数组一旦创建,其大小不能改变(Java 静态数组)。

Initialization fills elements with default values: 0 for numeric arrays, false for boolean, null for object types in Java. In pseudocode, uninitialized elements may be considered undefined. Always ensure you understand the data type and default values in a given exam question.

初始化会使用默认值填充元素:Java 中数值数组为 0,布尔数组为 false,对象类型为 null。在伪代码中,未初始化的元素可能被视为未定义。务必在给定的考试题目中理解数据类型和默认值。


Published by TutorHao | IB 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