SDD5 — Parallel Arrays
- I can describe what a parallel array is and explain why it is used
- I can implement parallel 1D arrays in Python and keep them correctly in sync
- I can trace and explain code that reads and writes data across parallel arrays using a common index
- I can explain, using an example, why the same index across two or more arrays refers to the same real-world item
- I can write Python code that declares, populates, and traverses parallel 1D arrays using a fixed loop
- I can trace through code using parallel arrays and correctly state the output, including a running total
Key vocabulary
Storing related data with parallel arrays
What is a parallel array?
A single 1D array can only store one attribute — one list of values. Most real problems need to store several different attributes about the same set of items: a name, a price, a quantity in stock, and so on. A parallel array solves this by using two or more separate 1D arrays, one per attribute, where the same index position in every array refers to the same real-world item. If itemNames[2] is "Chocolate", then itemPricesPence[2] and itemStock[2] must also describe that same chocolate — not some other item. Nothing in Python links the arrays together automatically; the relationship exists only because the programmer is careful to keep every array the same length, in the same order, and always indexed with the same counter variable.
Why use parallel arrays instead of one array?
Parallel arrays let a program model several attributes of the same set of items using only simple 1D array syntax, without needing a more advanced structure. This makes them a natural stepping stone before records and arrays of records (SDD6), which group all the attributes of one item together in a single structured variable instead of splitting them across separate arrays. Parallel arrays are simple to declare and easy to traverse with a single fixed loop, which is exactly why they appear in the Higher specification as their own named data structure, separate from records.
Declaring and populating parallel arrays in Python
In Python, each array in a parallel set is declared as its own list, using square brackets. For example, a small tuck shop stock system might use three separate lists — one for names, one for prices, and one for stock levels — created in the same order so that position 0 in every list describes the same item, position 1 describes the next item, and so on. The three lists must always be built and updated together: adding, removing, or reordering an item in one list without doing the exact same thing, at the exact same position, in every other list is the single most common way parallel arrays break.
Traversing parallel arrays with a common index
Once several arrays are parallel, a fixed loop can read from all of them at once by using one shared index variable across every array in the loop body. On each pass of the loop, the same value of that index variable is used to look up the matching element in every parallel array, so all the values read together on a single pass genuinely describe one item. This single-index traversal pattern is the foundation for later standard algorithms — linear search, finding a minimum or maximum, and counting occurrences (SDD13–14) — which all rely on being able to look up several related values using one matching index at a time.
Worked examples
itemNames = ["Crisps", "Juice", "Chocolate", "Water"] itemPricesPence = [60, 90, 75, 50] itemStock = [24, 15, 30, 40]
i, to print every item's full details on one line:
for i in range(len(itemNames)):
print(itemNames[i], "costs", itemPricesPence[i], "pence, stock:", itemStock[i])i = 2, itemNames[2] is "Chocolate", itemPricesPence[2] is 75, and itemStock[2] is 30 — the same index gives three facts about the same item.search = "Juice"
for i in range(len(itemNames)):
if itemNames[i] == search:
print("Price:", itemPricesPence[i])itemNames[i] against search on every pass, but never looks at itemPricesPence directly for the comparison.i = 1, itemNames[1] equals "Juice", so the condition is true, and the same index, 1, is then used to read itemPricesPence[1].Price: 90 — the match was found in one array, but the shared index i was used to retrieve the related value from the other array. This is the same principle behind linear search, covered later in SDD13.totalStock = 0
for i in range(len(itemStock)):
totalStock = totalStock + itemStock[i]
print(totalStock)itemStock = [24, 15, 30, 40]:i=0: itemStock[0]=24 → totalStock = 0 + 24 = 24 i=1: itemStock[1]=15 → totalStock = 24 + 15 = 39 i=2: itemStock[2]=30 → totalStock = 39 + 30 = 69 i=3: itemStock[3]=40 → totalStock = 69 + 40 = 109
i = 3 (there are 4 elements, indices 0–3), and the final printed value is 109.bookTitles = ["Wasp Factory", "Room", "1984", "Educated"]dueDates = ["12 Jul", "15 Jul", "18 Jul", "20 Jul"]Write a fixed loop that prints, for every book, a line in the form
Title: <title> — Due: <date>.
- Letting parallel arrays become different lengths. If one array gains or loses an element without the others changing to match, the same index no longer refers to the same item across all arrays.
- Forgetting Python indexing starts at 0. Using an index that is one too high or too low is a common off-by-one error when reading or searching parallel arrays.
- Updating only one array when an item changes. Appending, inserting, or removing an item in one array without doing the identical operation at the identical position in every other array breaks the parallel relationship.
- Assuming the arrays are automatically linked. Python does not know the arrays are related — the programmer must always use the same index variable deliberately across every array in the group.
- Confusing parallel arrays with records. Parallel arrays keep data in several separate arrays linked only by a shared index; a record groups all of one item's data into a single structured variable, which is covered in SDD6.
When asked to implement or trace code using parallel arrays, always use exactly one loop counter variable to index every array in the group on each pass. Introducing a second, separate counter — even by accident — breaks the implicit link between arrays and is one of the most common ways marks are lost in this topic.
Task Set A — Core questions
itemNames = ["Crisps", "Juice", "Chocolate", "Water"] and itemPricesPence = [60, 90, 75, 50], what is the value of itemPricesPence[2]?itemNames using itemNames.append("Crisps XL") but forgets to add a matching new price to itemPricesPence. What is the most likely consequence?itemStock = [24, 15, 30, 40] and the fixed loop for i in range(len(itemStock)): totalStock = totalStock + itemStock[i], starting with totalStock = 0, what is the final value of totalStock?itemNames and itemPricesPence became different lengths. (3 marks)bookTitles = ["Wasp Factory", "Room", "1984"] and bookAuthors = ["Iain Banks", "Emma Donoghue", "George Orwell"], then uses a fixed loop to print each title with its author in the form <title> by <author>.bookTitles = ["Wasp Factory", "Room", "1984"]
bookAuthors = ["Iain Banks", "Emma Donoghue", "George Orwell"]
for i in range(len(bookTitles)):
print(bookTitles[i], "by", bookAuthors[i])
itemNames[i] == "Chocolate" when i = 2. Using itemStock = [24, 15, 30, 40], which value correctly gives the stock of chocolate?Task Set B — Extension
itemNames, itemPricesPence, and itemStock into a single array of records instead (a topic in the next lesson). Suggest one advantage and one disadvantage of parallel arrays compared to a single array of records.Higher Computing Science → Software Design & Development → SDD5
Double period. This is the first Implementation-strand lesson using real Python code rather than pseudocode/design — worth flagging explicitly, since pupils have been working in pseudocode/structure diagrams/wireframes since SDD3–4.
Suggested timing: 10 min warm-up + vocab · 25 min notes + examples 1–2 (live-code the tuck shop arrays in PyCharm alongside the slides) · 15 min example 3 trace table (do this one on the whiteboard together before pupils see the answer) · 10 min "now you try" · 45 min Task Set A · remaining time Task Set B / homework.
Key misconception: pupils often assume Python automatically keeps separate lists "linked" because they were declared near each other, or that appending to one list updates the others. Live-demonstrate breaking a parallel array on purpose (append to one list only) and show the resulting mismatch when the loop runs.
SQA command words covered: describe, explain, implement, trace.
Extension suggestion: Extension 3 deliberately connects to the Advanced Higher 2D array content — useful for stretching pupils who ask "why not just use a 2D array?", a question that comes up almost every year.