OCR H446 · A Level Computer Science · ~12 min read
Notes
Video
Slides
Worksheet
Quiz
Data Structures Overview
A data structure is a way of organising and storing data so it can be accessed and modified efficiently. Choosing the right data structure is fundamental to good algorithm design. Different structures make different operations (insertion, deletion, searching) faster or slower.
Arrays
An array is a fixed-size, ordered collection of elements all of the same data type, stored in contiguous memory locations.
Static: size is fixed at declaration — cannot grow or shrink at runtime
Zero-indexed (in most languages): first element is at index 0
Direct access (O(1)): any element can be accessed instantly using its index
A tuple is an ordered, immutable collection — once created, it cannot be changed (no adding, removing, or modifying elements):
Can contain mixed types
More memory-efficient than lists (immutability allows optimisation)
Use cases: coordinates (x, y, z), RGB colour values, database rows, function returning multiple values
Accessed by index like arrays, but cannot be modified
point = (4, 7, -2) -- x, y, z coordinates
colour = (255, 128, 0) -- RGB orange
print(point[0]) -- 4-- point[0] = 10 ← Error! Tuples are immutable
Records
A record (called a struct in some languages) is a collection of named fields which can be of different types, grouped together to represent a single entity:
Each field has a name and a data type
Fields are accessed by name, not by index
Similar to a row in a database table
Used to represent real-world objects: Student, Employee, Product
-- Define a record typeTYPE Student
name : String
age : Integer
grade: Real
ENDTYPE-- Create and use a record
s.name = "Alice"
s.age = 17
s.grade = 89.5
Comparison Table
Feature
Array
List
Tuple
Record
Size
Fixed
Dynamic
Fixed
Fixed
Type
Homogeneous
Mixed
Mixed
Mixed (named)
Mutable?
Yes
Yes
No
Yes
Access
By index
By index
By index
By field name
Use case
Fixed collection same type
Variable-length ordered data
Immutable grouped values
Represent a real-world object/entity
Exam tip: The key distinction for tuples is immutability — once created, you cannot change them. If asked why tuples are used instead of lists, the answer is: immutability guarantees data integrity, and they use less memory. Coordinates, RGB values, and database records are classic tuple examples.
Exam tip: Arrays store elements in contiguous memory, which enables O(1) direct access via index. The address formula B + (i × w) is important for computing element addresses in memory — this can appear in exam questions.
⚠ Common Mistakes
Saying arrays can hold mixed types — standard arrays are homogeneous (all same type). Lists/tuples can hold mixed types.
Confusing lists (dynamic, mutable) with tuples (fixed-size, immutable) — the key difference is mutability.
Forgetting zero-indexing — in most pseudocode and languages, the first element is at index 0, not 1.
✓ Notes completed!
▶
Video coming soon
Click to advance · Arrow keys also work
Click slide or press arrow keys to navigate
✍
Worksheet — 1.4.2a Arrays, Lists, Tuples and Records
8 questions · 20 marks · instantly marked
Q1State two differences between an array and a list.[2 marks]
✓ Mark scheme
Any two of: Arrays are fixed-size (static); lists are dynamic (can grow/shrink) [1]. Arrays are homogeneous (all same type); lists can hold mixed types [1]. Arrays use contiguous memory with direct index access; list implementations may use dynamic arrays or linked nodes [1].
Q2An array starts at base address 2000. Each element is 4 bytes. Calculate the memory address of the element at index 7.[2 marks]
Q3Explain what is meant by a tuple being immutable and give one situation where a tuple would be preferred over a list.[3 marks]
✓ Mark scheme
Immutable means the contents of the tuple cannot be changed after it is created — elements cannot be added, removed, or modified [1]. A tuple would be preferred when the data should not change — e.g. storing a 2D coordinate (x, y) or an RGB colour value (r, g, b) [1] — because immutability provides data integrity guarantees and tuples use less memory than lists [1].
Q4A 2D array has 5 rows and 4 columns. The base address is 1000 and each element is 2 bytes. Using row-major ordering, calculate the address of element [2][3].[3 marks]
Q5Describe a record data structure and explain how it differs from an array. Give an example of a suitable record in a school context.[4 marks]
✓ Mark scheme
A record is a data structure that groups together related fields of different types under a single entity; each field has a name and type [1]. A record differs from an array in that: fields can be of different types (arrays are homogeneous) [1]; fields are accessed by name rather than index [1]. Example: a Student record with fields name (String), age (Integer), score (Real) — representing a single student's information [1].
Q6A programmer stores the (latitude, longitude) coordinates of a city as a Python tuple rather than a list. Justify this choice.[2 marks]
✓ Mark scheme
A tuple is immutable — the coordinates of a city are fixed and should not be accidentally modified [1]; using a tuple prevents inadvertent changes that could corrupt the data, and tuples also use less memory than equivalent lists [1].
Q7Explain why arrays provide O(1) (constant time) access to any element, regardless of the array size.[2 marks]
✓ Mark scheme
Arrays store elements in contiguous (consecutive) memory locations [1]. Given the base address and element size, the address of any element can be calculated directly using the formula B + (i × w) — this is a single arithmetic operation, taking constant time regardless of the array's length [1].
Q8A teacher needs to store, for each student: their name, form group, 5 subject grades, and whether they receive free school meals. Design a record structure for this, including field names and data types.[4 marks]
✓ Mark scheme
Suitable record with correct types: name: String [1]; formGroup: String (or Char) [1]; grades: Array[1..5] of Integer/Real (or 5 separate grade fields) [1]; freeMeals: Boolean [1]. Award marks for each correctly named and typed field — field names may vary but types must be appropriate.
Topic Quiz
1 of 15
You scored
out of 15
🎯
Mini Test — 1.4.2a Data Structures
10 questions · 10 marks · 10 minutes
5 MCQ + 5 short answer
⏱10:00
10 marks
Section A — Multiple Choice
Q1Which data structure is immutable (cannot be changed after creation)?
Q2An array has base address 500, element size 4 bytes. What is the address of element at index 3?
Q3Which data structure allows fields of different types, accessed by name?
Q4Why can arrays provide O(1) random access?
Q5A 2D array has 3 rows and 5 columns, base address 200, element size 1 byte. Address of element [1][3] (row-major)?
Section B — Short Answer
Q6State one advantage of a list over an array.
Mark schemeLists are dynamic — they can grow or shrink at runtime as elements are added or removed. This avoids wasting memory on unused allocated space or running out of space as with fixed-size arrays. Lists can also hold mixed types. [1 mark]
Q7What is the difference between a list and a tuple?
Mark schemeBoth are ordered collections that can hold mixed types. The key difference: a list is mutable (elements can be added, removed, or changed); a tuple is immutable (contents cannot be changed after creation). Tuples also use less memory. [1 mark]
Q8Give a real-world example where a record data structure would be appropriate.
Mark schemeAny suitable example: Employee record (name, ID, department, salary, startDate); Patient record (name, dateOfBirth, NHSnumber, conditions); Product record (productCode, name, price, stockLevel). The key is that different field types represent one real-world entity. [1 mark]
Q9What is meant by a homogeneous data structure?
Mark schemeA homogeneous data structure stores elements that are all of the same data type — for example, an array of integers or an array of strings. This contrasts with heterogeneous structures (like lists, tuples, records) that can store values of different types. [1 mark]
Q10An array of 10 integers starts at address 1000 and each integer takes 4 bytes. What is the address of the last element?
Mark schemeLast element is at index 9 (zero-indexed). Address = 1000 + (9 × 4) = 1000 + 36 = 1036. [1 mark]