All subjects · Computer Science · WCP01 Principles of Computer Science
Data structures: arrays, lists, dictionaries, records, tuples and sets
Edexcel IAL Computer Science · WCP01 Principles of Computer Science
A data structure organises related data so it can be used efficiently. You need to know the properties of six structures and hand-trace operations on them (spec point 4.2.1). Code examples use Python, as in the Pearson papers.
Arrays and lists
- Array: a fixed-size collection of elements of the same data type, stored in contiguous memory and accessed by an index (starting at 0). Fast direct access; but the size cannot change and every element must be the same type. A two-dimensional array is a grid accessed by [row][column].
- List: an ordered collection whose size can change (items can be appended, inserted and removed). In Python, lists can hold mixed types. Flexible; but inserting or deleting in the middle means moving the later items, and lists use more memory than arrays.
Dictionaries, records, tuples and sets
- Dictionary: a collection of key: value pairs. Keys are unique and are used to look values up directly, for example {'Paris': 2.1, 'Cairo': 10.0}. Fast lookup by key; no index order to rely on for position, and keys cannot repeat.
- Record: a single item made of named fields that can be of different types, for example a student record with name (text), age (integer) and enrolled (Boolean). Several records form a table or file.
- Tuple: an ordered collection that is immutable (cannot be changed after creation), for example a coordinate (3, 4). Safe for fixed data; must be rebuilt to change.
- Set: an unordered collection of unique items, with no index. Fast membership tests and removal of duplicates.
Set operations
For A = [2, 4, 6, 8, 10] and B = [3, 6, 9] (written in order here, although sets are unordered):
| Operation | Meaning | Result |
|---|---|---|
| Union A ∪ B | Items in A or B or in each | [2, 3, 4, 6, 8, 9, 10] |
| Intersection A ∩ B | Items in A and also in B | [6] |
| Difference A - B | Items in A but not in B | [2, 4, 8, 10] |
Tracing a 2D array
grid = [[3, 8, 1], [6, 2, 9], [4, 7, 5]]
- grid[0][2] is row 0, column 2: 1
- grid[2][1] is row 2, column 1: 7
- After grid[1][0] = grid[1][0] + grid[0][1], the value at [1][0] becomes 14.
Always check whether the question indexes from 0, as Python does.
Worked example
Show the contents of the dictionary after these operations. cities = {'Berlin': 3.6, 'Lagos': 15.4} cities['Lima'] = 10.1 del cities['Berlin'] cities['Lagos'] = 16.0
- Start: {'Berlin': 3.6, 'Lagos': 15.4}
- Add Lima: {'Berlin': 3.6, 'Lagos': 15.4, 'Lima': 10.1}
- Delete Berlin: {'Lagos': 15.4, 'Lima': 10.1}
- Assigning to an existing key replaces its value: {'Lagos': 16.0, 'Lima': 10.1}
Answer: {'Lagos': 16.0, 'Lima': 10.1}
Check yourself
- grid = [[3, 8, 1], [6, 2, 9], [4, 7, 5]]. What is grid[1][2]?
Show answer
9. Row 1 is [6, 2, 9]; column 2 is 9.
- grid = [[3, 8, 1], [6, 2, 9], [4, 7, 5]]. What is the sum of row 2?
Show answer
16. 4 + 7 + 5 = 16.
- grid = [[3, 8, 1], [6, 2, 9], [4, 7, 5]]. What is the total of column 0?
Show answer
13. 3 + 6 + 4 = 13.
- A = {1, 3, 5, 7, 9} and B = {3, 4, 5, 6}. List the intersection of A and B in ascending order, separated by commas.
Show answer
3, 5. Items in A and also in B: 3, 5.
- A = {1, 3, 5, 7, 9} and B = {3, 4, 5, 6}. How many items are in the union of A and B?
Show answer
7. Union = [1, 3, 4, 5, 6, 7, 9], which has 7 items (duplicates count once).
- Which data structure cannot be changed after it is created?
- Tuple
- List
- Dictionary
- Set
Show answer
Tuple. Tuples are immutable.
- Which data structure is best for looking up a country's population from the country's name?
- Tuple
- One-dimensional array of integers
- Dictionary
- Set
Show answer
Dictionary. The name is a unique key mapped to its value.
- What is a record?
- An unordered collection of unique values
- A fixed-size collection of items of one type accessed by index
- A collection that cannot contain duplicates
- A single item made of named fields that can have different data types
Show answer
A single item made of named fields that can have different data types. For example name (text), age (integer), enrolled (Boolean).
Sources
Last updated 8 November 2026. Spotted a mistake? Tell us.