SLIDE 1 / 10
CSZone.co.uk
OCR H446 · Component 1 · 1.4.2

Arrays, Lists,
Tuples & Records

OCR A Level Computer Science · cszone.co.uk
H446 SpecA Level
Learning Objectives

By the end of this topic you will be able to:

Describe arrays (1D and 2D) and explain how elements are accessed
Describe lists and compare them to arrays
Describe tuples and explain when they are used
Describe records and explain how they store related data of different types
Arrays

Arrays (1D and 2D)

An array is a static, ordered, fixed-size data structure that stores elements of the same data type in contiguous memory. Elements are accessed by index (usually 0-based in most languages).
1D Array
scores = [87, 92, 74, 66, 91]
scores[0] = 87
scores[3] = 66
2D Array (Matrix)
grid[2][3] accesses
row 2, column 3
grid = [[1,2,3],[4,5,6],[7,8,9]]
grid[1][2] = 6
Arrays have O(1) random access — any element can be reached directly using its index. They are fixed in size; adding or removing elements requires creating a new array.
Lists

Lists

A list is a dynamic, ordered data structure. Unlike arrays, lists can grow or shrink at runtime (elements can be added and removed). Lists may store elements of different data types depending on the language.
Dynamic size: elements can be appended, inserted, or deleted without declaring a fixed size in advance. Python lists are a common example.
Linked list implementation: each element (node) stores data and a pointer to the next node. This allows efficient insertions/deletions but O(n) access time (must traverse from head).
Advantage over Array
Dynamic — no need to know size in advance; efficient insertions
Disadvantage vs Array
Slower random access (O(n) for linked lists); overhead of pointers
Tuples & Records

Tuples and Records

Tuple
An immutable ordered collection of elements (cannot be modified after creation). May contain mixed data types. Used when data should not change: coordinates, RGB values, database rows returned from a query.

point = (3, 7)
colour = (255, 128, 0)
Record
A record (struct) stores a fixed set of related fields of different data types under one name. Like a row in a database table. Used for complex real-world entities.

Student record:
name: String
age: Integer
grade: Real
Comparison

Choosing the Right Structure

StructureSizeTypesMutableUse When
ArrayFixedSameYes (elements)Known fixed-size collection
ListDynamicMixed (Python)YesCollection grows/shrinks
TupleFixedMixedNoData must not change
RecordFixed fieldsMixedYesGroup related different-type data
Exam Practice
OCR H446 Style · 4 marks
State two differences between an array and a list as data structures. For each difference, explain why it might influence a programmer's choice of structure.
[4 marks]
2
Size: an array is fixed in size (must be declared with a set number of elements); a list is dynamic (can grow or shrink at runtime). If the number of items is not known in advance — e.g. reading an unknown number of student names — a list is preferable because it does not require a size declaration.
2
Data types: arrays store elements of the same data type; lists (in some languages, e.g. Python) can store elements of different types. If a programmer needs to store mixed-type data together without using records, a list gives more flexibility.
Common Mistakes

Don't Lose Marks

!
Saying a tuple is the same as an array — the key distinguishing feature of a tuple is that it is immutable (cannot be changed after creation). Arrays are mutable. This is the distinction OCR tests — always state immutability when describing tuples.
!
Saying arrays can store different data types — arrays are homogeneous (all elements same type). If you need mixed types in an ordered collection, use a tuple or list. If you need named fields of mixed types, use a record.
!
Describing a 2D array index as column then row — the convention is array[row][column]. For example grid[2][3] means row 2, column 3. This matters in questions asking you to trace 2D array operations.
1.4.2a Complete
Well done! ✓
Arrays, Lists, Tuples and Records
Return to lesson to continue