Arrays and records
A data structure organises related data so a program can store and retrieve it efficiently. AQA GCSE covers two: arrays (one and two dimensional) and records.
Arrays (1D)
A 1-D array is an ordered list of items of the same type, accessed by an integer index. AQA pseudocode is 0-indexed, so the first element is at position 0.
SET names TO ["Aisha", "Ben", "Chloe", "Dan"]
OUTPUT names[0] -- prints "Aisha"
OUTPUT names[3] -- prints "Dan"
SET names[1] TO "Ben Senior"
- The whole array has a size —
LEN(names)returns 4. - Use a loop to process every element:
FOR i FROM 0 TO LEN(names) - 1
OUTPUT names[i]
ENDFOR
Why use arrays?
- Fixed memory — array contents are contiguous in memory; access by index is constant-time.
- Loops over data — easy to iterate.
- Algorithms — searches and sorts are written for arrays.
2D arrays
A 2-D array is a grid (rows × columns). It's like an array of arrays. Access uses two indices: grid[row][col].
SET seating TO [
["Anna", "Ben", "Carla"],
["Dani", "Eli", "Faye"]
]
OUTPUT seating[0][0] -- "Anna"
OUTPUT seating[1][2] -- "Faye"
Use a nested loop to process every cell:
FOR row FROM 0 TO LEN(seating) - 1
FOR col FROM 0 TO LEN(seating[row]) - 1
OUTPUT seating[row][col]
ENDFOR
ENDFOR
Common 2D-array uses: chess boards, spreadsheets, image pixel grids.
Records
A record groups together related data of possibly different types under one name. Each piece is a field with its own name. (In some languages this is called a "struct" or "object".)
RECORD Student
name : string
age : integer
grade : character
ENDRECORD
SET pupil1 TO Student("Aisha", 15, 'A')
OUTPUT pupil1.name -- "Aisha"
OUTPUT pupil1.grade -- 'A'
Records are perfect when each item has many attributes — a Book has title, author, ISBN, year — that don't share a type.
Choosing array vs record
- All items the same type, ordered by position → array.
- Several different attributes per item → record.
- Many items, each with several attributes → array of records.
RECORD Student ... ENDRECORD
SET students TO [Student("Aisha", 15, 'A'), Student("Ben", 14, 'B'), ...]
OUTPUT students[0].name
⚠Common mistakes— Pitfalls
- Off-by-one indexing. First index is 0; last is LEN − 1.
- Index out of bounds.
names[10]on a 4-element list crashes. - Confusing rows and columns in 2D arrays.
grid[row][col]— row first. - Forgetting that arrays are fixed-size in some languages (Python lists grow; static arrays don't).
- Comparing two arrays with = rarely works — usually compares references, not contents.
✦Worked example— Worked examples
Example 1. Find the largest number in an array.
SET largest TO numbers[0]
FOR i FROM 1 TO LEN(numbers) - 1
IF numbers[i] > largest THEN
SET largest TO numbers[i]
ENDIF
ENDFOR
OUTPUT largest
Example 2. Count how many "A" grades in a 2D array results[year][student]:
SET count TO 0
FOR y FROM 0 TO LEN(results) - 1
FOR s FROM 0 TO LEN(results[y]) - 1
IF results[y][s] = 'A' THEN
SET count TO count + 1
ENDIF
ENDFOR
ENDFOR
Example 3. Define a Book record and store an array of them:
RECORD Book
title : string
author : string
year : integer
ENDRECORD
SET library TO [
Book("Dune", "Herbert", 1965),
Book("1984", "Orwell", 1949)
]
➜Try this— Quick check
What does grid[2][1] refer to in a 4 × 3 grid? Row 2 (third row, since 0-indexed), column 1 (second column).
AI-generated · claude-opus-4-7 · v3-deep-computer-science