Choose the structure from the question
A data structure organises related values so a program can select and use the required information. In our worked library, a book label is a string, stock counts are stored in arrays, and a record groups named facts about one book. These structures answer different questions; they are not interchangeable names for a single value.
A string is an ordered sequence of characters, including any stored spaces or punctuation. An array is an indexed collection: an index identifies a position, and the element at that position holds a value. A record uses named fields, such as title, copies and loanable, about one entity. Its fields may have different types. Choose the structure before choosing a position or field.
| Library question | Structure | Selector |
|---|---|---|
| Which character is in the book label? | String: BOOK 27 | A stated character position |
| How many copies of the second book are at North? | One-dimensional stock array | One index |
| How many copies are at a particular branch for a particular book? | Two-dimensional stock array | Row and column indices |
| Does library policy allow this book to be borrowed? | Record describing one book | Named loanable field |
Inspecting and joining strings
A string is an ordered sequence of characters. Length counts characters, including spaces. Position/indexing identifies where a character occurs. A substring, also called a slice, selects a consecutive part. Concatenation joins strings in order.
Always use the indexing and endpoint convention specified in the question. For this example, positions start at zero and substring length means the number of characters to take.
| Operation on PORT-27 | Result |
|---|---|
| Length | 7 |
| Character at index 0 | P |
| Substring from index 5, length 2 | 27 |
| Concatenate BAY- and 27 | BAY-27 |
One-dimensional arrays, grids and records
An array stores an ordered collection accessed by index. In the OCR model an array has a fixed length. A two-dimensional array uses two indices, often row then column. Check index bounds: a zero-indexed array of length four has valid indices 0 through 3.
A record groups named fields about one entity. A pupil record could contain a string name, an integer age and a Boolean consent flag. These fields may have different types. A table can be represented as rows of records or a two-dimensional collection, but its rows and columns must retain their meanings.
| Row | Column 0: Monday | Column 1: Tuesday |
|---|---|---|
| 0: Room A | 18 | 21 |
| 1: Room B | 17 | 20 |
Read, calculate, then store only the selected element
Use this stock-desk example. North has four integer counts: [8, 13, 5, 10]. Positions start at zero, so index 1 selects the second count, 13. Four delivered copies belong to that book. Read 13, calculate 13 + 4 = 17, then store 17 at index 1. A calculation and an assignment are different events.
After storage the array is [8, 17, 5, 10]. Its four positions have not changed; the last valid index remains 3. An array length counts elements, not total copies: neither 17 nor the sum of the counts is this array's length. OCR uses fixed-length arrays; all arrays in these worked examples also have explicitly fixed dimensions.
Replacing a count with zero keeps that element. For example, removing five copies from the five at index 2 would store zero there, not remove the position or shift the other counts. An assigned zero is different from a value that has not yet been assigned.
| Event | Temporary calculation | Still stored at index 1 |
|---|---|---|
| Before reading | Not calculated | 13 |
| Read index 1 | Read value 13 | 13 |
| Calculate 13 + 4 | 17 | 13 |
| Store at index 1 | 17 | 17 |
Keep row, column and named field distinct
Continue the library example with North as row 0 and South as row 1. Each of four columns identifies one book. The table below starts after North's delivery but before South's delivery. Indices are row first: row 1, column 0 selects 4; reversing those two valid indices selects North's 17 instead.
A delivery adds six to South's column-2 book. Select row 1, column 2, read 7, calculate 13, and store it at that intersection only. South becomes [4, 11, 13, 9]; North stays [8, 17, 5, 10]. Row 2 does not exist, so reversing [1,2] into [2,1] is invalid, not another way to address the same cell.
The selected book is River Walk. A record can represent its title as String, copies as Integer 13, and loanable as Boolean True. These are named fields of one entity, not adjacent array positions to guess. The loanable flag states a borrowing policy; a later copies update does not automatically recalculate that flag. If a system stores both a grid count and a separate record count, it must explicitly keep them consistent; the two storage locations are not automatically linked.
| Branch row | Book column 0 | Book column 1 | Book column 2 | Book column 3 |
|---|---|---|---|---|
| 0: North | 8 | 17 | 5 | 10 |
| 1: South | 4 | 11 | 7 | 9 |
Continue with your exam board
The course combines lesson videos, interactive activities, topic questions and original exam mocks. Sign in to use the learning tools and save your progress; your account’s course access applies.
Independent learning resources. Not endorsed by AQA or OCR. These public introductions complement the full course and the official specification.