SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
CAIE 9618 · Paper 2 · Topic 2.2.2

Arrays

1D Arrays · 2D Arrays · Declaration · Common Array Algorithms

CSZone Cambridge International AS & A Level Computer Science 9618
What is an Array?

A Fixed-Size Collection of Same-Type Items

An array is a static data structure that stores a fixed number of elements of the same data type, accessed via an index. In CAIE pseudocode, arrays are 1-indexed by default.
Static — size is fixed at declaration and cannot change at runtime
Homogeneous — all elements must be the same data type
Indexed — elements accessed by position (index). O(1) access time.
Contiguous memory — elements stored in consecutive memory locations
1D Arrays

Declaration and Access

DECLARATION
DECLARE scores : ARRAY[1:5] OF INTEGER
Creates array of 5 integers, indices 1–5
ASSIGN AND ACCESS
scores[1] <- 90
scores[2] <- 75
OUTPUT scores[1] // 90
scores array visualised:
9075886295
[1][2][3][4][5]
TRAVERSE WITH FOR LOOP
FOR i <- 1 TO 5
OUTPUT scores[i]
NEXT i
2D Arrays

Rows and Columns (Matrix)

A 2D array is like a table (matrix). Access by [row, col]. Useful for grids, seating plans, game boards, pixel data.
DECLARATION (3 rows × 4 cols)
DECLARE grid : ARRAY[1:3,1:4] OF INTEGER
ACCESS AND ASSIGN
grid[1,1] <- 10 // row 1 col 1
grid[2,3] <- 55 // row 2 col 3
OUTPUT grid[1,1] // 10
TRAVERSE 2D ARRAY (nested loops)
FOR row <- 1 TO 3
FOR col <- 1 TO 4
OUTPUT grid[row,col]
NEXT col
NEXT row
Outer loop = rows, inner loop = columns. Total iterations = rows × cols.
Common Array Algorithms

Sum, Average, Count, Max/Min

SUM AND AVERAGE
total <- 0
FOR i <- 1 TO n
total <- total + a[i]
NEXT i
avg <- total / n
FIND MAXIMUM
max <- a[1] // seed with first
FOR i <- 2 TO n
IF a[i] > max THEN
max <- a[i]
ENDIF
NEXT i
OUTPUT max
Exam Practice

Cambridge-style questions

Question 1
A school has 30 students and 5 subjects. Write pseudocode to declare a 2D array to store all their marks, and output the average mark for student 1 across all subjects.
5 marks
DECLARE marks : ARRAY[1:30,1:5] OF INTEGER // 1 mark — correct dimensions
DECLARE total, j : INTEGER
total <- 0 // 1 mark — initialise total
FOR j <- 1 TO 5 // 1 mark — correct loop
total <- total + marks[1,j] // 1 mark — correct 2D access
NEXT j
OUTPUT total / 5 // 1 mark — correct average
Common Mistakes

Don't lose easy marks

1
Using 0-based indexing — CAIE pseudocode uses 1-based indexing by default. arr[0] does not exist unless you declare ARRAY[0:n-1]. Always declare the start index explicitly.
2
Forgetting to specify the type — the CAIE declaration requires "OF INTEGER" or "OF STRING" etc. Writing DECLARE arr : ARRAY[1:10] without OF TYPE loses a mark.
3
Confusing row and column order in 2D arrays — CAIE convention is [row, col]. ARRAY[1:30, 1:5] means 30 rows and 5 columns. marks[2, 3] is row 2, column 3 (student 2's third subject).
Topic Summary — 2.2.2

What You Need to Know

1D ARRAY
DECLARE name : ARRAY[1:n] OF TYPE
Access: name[i] · 1-indexed in CAIE
Traverse: FOR i <- 1 TO n
2D ARRAY
DECLARE name : ARRAY[1:rows, 1:cols] OF TYPE
Access: name[row, col]
Traverse: nested FOR loops (outer=rows)
COMMON ALGORITHMS
Sum: accumulate total in loop
Average: total / n
Max/Min: seed with first, compare rest
Count: increment counter on condition
CSZone

Next Video

2.2.3
Records
TYPE…ENDTYPE · Fields · Arrays of Records
Head to CSZone.co.uk for the complete worksheet, quiz, and interactive tools