Arrays (of up to 3 dimensions), records, lists, tuples
1.4.2 Data Structures
Practise exam questionsData Structures — Note 1 of 3
Candidates should be able to describe what is meant by arrays (up to 3 dimensions), records, lists and tuples. They are expected to be able recognise when they can be used and incorporate them in their programs to store data
Data structures organise related data so it can be processed efficiently. Arrays hold a fixed number of items of the same type; records group related fields of different types; lists are dynamic; tuples are fixed and cannot be changed.
Exam tipCommon mistake
A static (fixed size) data structure holding items of the same data type, accessed by index. OCR arrays are zero-indexed.
board[row, col]); a 3D array adds a third index, e.g. sales[shop, month, product].A data structure that groups related fields, which can have different data types, e.g. a student record with name (string), age (integer) and enrolled (Boolean).
A dynamic data structure whose size can change as items are added or removed; items can be of different types in languages like Python.
An ordered collection of items that is IMMUTABLE: once created, its items cannot be changed, added or removed.
grid = [[0] * 3 for _ in range(3)] # 2D array (3 x 3)
grid[1][2] = 5
student = {"name": "Sam", "age": 17, "enrolled": True} # record
scores = [12, 7, 9] # list (dynamic)
scores.append(15)
origin = (0, 0) # tuple (immutable)
# origin[0] = 5 would cause an errorReady to test yourself?
Practise 1.4.2 questions