A data structure is an organised way of storing and managing data so it can be accessed and modified efficiently. Edexcel 1CP2 requires knowledge of arrays and records.
An array is an ordered collection of elements of the same data type, stored in consecutive memory locations. Arrays have a fixed size (in most languages).
A 1D array (single list) is like a row of boxes, each with an index number.
| Index | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| Value | "Ali" | "Beth" | "Carl" | "Dana" | "Eve" |
names[0] returns "Ali" · names[3] returns "Dana" (zero-indexed)
names = ["Ali","Beth","Carl","Dana","Eve"]A 2D array is an array of arrays — like a table with rows and columns. Used for grids, matrices, and seating plans.
| Col 0 | Col 1 | Col 2 | |
|---|---|---|---|
| Row 0 | 10 | 20 | 30 |
| Row 1 | 40 | 50 | 60 |
grid[1][2] returns 60 (row 1, column 2)
array[row][col]A record is a data structure that groups together related data items of different data types under one name. Think of it like a row in a database table.
| Field | name | age | height | isMember |
|---|---|---|---|---|
| Data type | String | Integer | Real | Boolean |
| Example value | "Ali" | 16 | 1.72 | TRUE |
In Edexcel pseudocode:
RECORD Student
name : STRING
age : INTEGER
height : REAL
ENDRECORD
| Feature | Array | Record |
|---|---|---|
| Data types | All the same | Can be mixed (different fields) |
| Access | By index number | By field name |
| Use case | List of similar items | Single entity with multiple attributes |
| Example | List of 30 test scores | One student's name, age, score |
grid[row][col] not grid[col][row]8 questions · Arrays & Records
scores contains: [45, 72, 88, 91, 55]. What is the value of scores[3]?[1]grid is: [[1,2,3],[4,5,6],[7,8,9]]. What is grid[2][1]?[1]temperatures containing five values: 21.3, 19.8, 22.5, 18.0, 20.1[2]| Term | Definition |
|---|
10 minutes · Exam-style questions