Learning Objectives
By the end of this lesson, you should be able to:
- declare and use one-dimensional (1D) and two-dimensional (2D) arrays
- understand the use of arrays
- write values into an array and read values from an array using iteration
- identify the correct row and column when using a 2D array
- trace array accesses and assignments using an index
- recognise the difference between array indexing conventions and follow the convention shown in the question
Key Terms
Array
An ordered, static set of elements stored in a fixed-size memory location.
Index
The position used to identify an individual array element.
1D array
A linear array with one index.
2D array
An array organised as rows and columns, requiring two index values.
Zero-indexed
The first element is at index 0.
Nested loop
A loop placed inside another loop, commonly used to traverse 2D arrays.
1D Arrays — Think in Boxes
The source material describes an array as an ordered, static set of elements in a fixed-size memory location. A 1D array is linear: imagine a single row of boxes, each identified by an index.
| Index | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| Value | B | E | A | D | S |
In this example, the value at index 3 isD. The array has length 5.
Python representation
The Save My Exams notes use a Python list to represent a 1D array. Python lists are more flexible than a strict fixed-size array representation, but they are used here to demonstrate the array concepts.
array = [1, 2, 3, 4, 5]
print(array[0]) # 1
print(array[2]) # 3
array[1] = 10
print(array) # [1, 10, 3, 4, 5]
length = len(array)
print(length) # 5Accessing usesarray[index]. Modifying usesarray[index] = newValue. Python useslen(array)to obtain the length in the examples.
Cambridge IGCSE pseudocode
DECLARE scores : ARRAY[0:4] OF INTEGER
scores ← [12, 10, 5, 2, 8]
colours[4] ← "Red" // index 4 is the 5th elementThe TED notes also show pseudocode declarations such asARRAY[1:30]. For exam questions, use the index range and index order that the question gives.
1D Array Explorer
Click an index to highlight the element.
Activity 1A: Find by index
Difficulty: Easy • Estimated time: 4 minutes
For scores = [12, 10, 5, 2, 8], what value is stored at index 3?
Activity 1B: Modify an element
Difficulty: Easy • Estimated time: 4 minutes
Change the value at index 2 in scores = [12, 10, 5, 2, 8] to 99. Write the Python assignment.
scores[2] = 99Check Your Understanding: 1D Arrays
1. What is an array?
- An array stores an ordered set of related elements.
- The source describes it as static and fixed-size in memory.
- Each element is accessed using an index.
- The core array representation stores elements of the same data type.
2. What does array[2] mean?
- It refers to the element at index 2.
- In a zero-indexed array, this is the third element.
- The index identifies which element should be accessed.
- The brackets show that an index is being used.
3. What is the difference between accessing and modifying an array element?
- Accessing reads the current value at an index.
- Modifying assigns a new value to a particular index.
- Python uses array[index] to access an element.
- Python uses array[index] = newValue to modify an element.
4. What does len(array) return in Python?
- It returns the number of elements in the list/array representation.
- For [1, 2, 3, 4, 5], the result is 5.
- It does not return the highest index.
- In a zero-indexed array of length 5, the highest index is 4.
2D Arrays — Rows + Columns
A 2D array adds another dimension to a 1D array. The source notes say it can be visualised as a table with rows and columns. To find a position, you move to the row and then across to the column.
| Column 0 | Column 1 | Column 2 | |
|---|---|---|---|
| Row 0 | 1 | 2 | 3 |
| Row 1 | 4 | 5 | 6 |
| Row 2 | 7 | 8 | 9 |
For example,array_2d[1][2]selects row 1, column 2 →6in the Python example.
Python example
array_2d = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
print(array_2d[0][0]) # 1
print(array_2d[1][2]) # 6A Python 2D array can be represented as a list containing inner lists. The outer list represents rows; each inner list represents the values in a row.
Cambridge pseudocode
DECLARE NamesAndNumbers : ARRAY[1:3, 1:2] OF STRING
// 3 rows → one for each person
// 2 columns → name and phone number
DECLARE players : ARRAY[1:4, 1:2] OF STRING
players[1,1] ← "Alice"
players[1,2] ← "25"
players[2,1] ← "Bob"
players[2,2] ← "30"
players[3,1] ← "Charlie"
players[3,2] ← "22"
players[4,1] ← "Daisy"
players[4,2] ← "28"
players[3,1] ← "Holly" // replace CharlieThe source also shows the same idea in Python:players[2][0] = "Holly", because Charlie is on the third row at Python index 2 and the name is in column 0.
2D Coordinate Explorer
Select a cell to see its row, column and value.
Activity 2A: Locate a value
Difficulty: Easy • Estimated time: 5 minutes
In array_2d = [[1,2,3],[4,5,6],[7,8,9]], write the Python expression for the value 8.
array_2d[2][1]Activity 2B: Read a table correctly
Difficulty: Easy • Estimated time: 4 minutes
A question uses [row][column]. Which cell does array[1][0] refer to in the table above?
Check Your Understanding: 2D Arrays
1. Why does a 2D array need two index values?
- It has two dimensions.
- One index identifies the row.
- The second index identifies the column.
- Both are needed to identify one cell.
2. What does array_2d[1][2] mean in the Python example?
- Select row index 1.
- Then select column index 2.
- The value found is 6.
- The first and second indexes are used in row-then-column order in this example.
3. How is a 2D array visualised in the notes?
- As a table.
- Rows are one dimension.
- Columns are the other dimension.
- Each cell stores one array element.
4. How can a name be replaced in the players 2D array?
- Identify the row containing the person.
- Identify the column containing the name.
- Assign the new string to that cell.
- In the source example, Python uses players[2][0] = "Holly".
Array Indexing — The Exam Trap
Indexing is one of the most common places to make an otherwise avoidable array mistake. The source notes explicitly warn that questions can use different index orders and that the exam question will give an example showing how the array is read.
1D
One index identifies one position.
2D
Two indexes identify row + column in the source example.
Zero-based versus one-based indexing
| Context | First element example | Important point |
|---|---|---|
| Python examples in the source | index 0 | Python indexing begins at 0 in the examples. |
| Cambridge pseudocode examples | ARRAY[1:30] / ARRAY[1:3,1:3] | The pseudocode examples can use ranges starting at 1. |
| Exam question | Follow the given example | Do not assume the order or starting index; use the convention shown in the question. |
Index Order Challenge
Choose the interpretation used by this lesson's Python example.
Activity 3A: Read the examiner's clue
Difficulty: Medium • Estimated time: 5 minutes
Why should you not automatically assume that the first index is always X or always the row?
- The source notes say some questions can be X,Y and others Y,X.
- The question's example demonstrates the order being used.
- Using the wrong order selects the wrong array element.
- Therefore, the example in the question must be checked before answering.
Check Your Understanding: Indexing
1. What is zero-indexing?
- The first element is at index 0.
- The second element is at index 1.
- For an array of length 5, the highest zero-based index is 4.
- Python uses zero-based indexing in the examples.
2. If the length of a zero-indexed array is 5, what are its valid indexes?
- 0
- 1
- 2
- 3
- 4
3. What should you do when an exam question's 2D index order is unclear?
- Look at the example given in the question.
- Identify which index corresponds to the row.
- Identify which index corresponds to the column.
- Use that same convention consistently in your answer.
Writing Values into an Array Using Iteration
The source lesson shows values being written into an array using a loop. Each value is calculated from the current index.
DECLARE myArray[5] : INTEGER
DECLARE index : INTEGER
FOR index FROM 1 TO 5
myArray[index] ← index * 10
NEXT indexThis creates the sequence 10, 20, 30, 40 and 50 when the pseudocode index runs from 1 to 5.
Python equivalent
my_array = [0] * 5
for index in range(5):
my_array[index] = (index + 1) * 10
print(my_array)
# [10, 20, 30, 40, 50]Notice the indexing difference: the Cambridge pseudocode example uses 1 to 5, while the Python example uses indexes 0 to 4.
Write-Into-Array Simulator
Activity 4A: Complete the loop
Difficulty: Medium • Estimated time: 5 minutes
Write the missing assignment so that each array element stores its index multiplied by 5.
FOR index FROM 1 TO 5
myArray[index] ← index * 5
NEXT indexActivity 4B: Trace one iteration
Difficulty: Easy • Estimated time: 3 minutes
What value is stored when index = 4 in myArray[index] ← index * 10?
Check Your Understanding: Writing Arrays
1. Why is a loop useful for filling an array?
- It can repeat the same assignment for many indexes.
- It reduces repeated code.
- The index can control which element is written.
- The value can be calculated from the current index.
2. What is the output of the source pseudocode when index runs from 1 to 5?
- 10
- 20
- 30
- 40
- 50
3. Why is the Python loop range(5) used in the equivalent example?
- Python uses zero-based indexes in the example.
- range(5) produces 0 through 4.
- Those five indexes represent the five array positions.
- (index + 1) is used so the calculated values are 10 through 50.
Reading Values from an Array Using Iteration
After storing values, a loop can be used to read each element. This is especially important in exam questions because many algorithms require every array element to be processed.
FOR index FROM 1 TO 5
OUTPUT "Value at index " + index + ": " + myArray[index]
NEXT indexfor index in range(5):
print("Value at index", index, ":", my_array[index])A nested loop can extend this idea to a 2D array: the outer loop visits rows and the inner loop visits columns.
for row in array_2d:
for item in row:
print(item, end=" ")
print()Activity 5A: Read every value
Difficulty: Easy • Estimated time: 4 minutes
Write Python that prints every value in [10, 20, 30, 40, 50] using a loop.
values = [10, 20, 30, 40, 50]
for value in values:
print(value)Activity 5B: Nested reading
Difficulty: Medium • Estimated time: 5 minutes
Write Python to print every value in the 3 × 3 array from the lesson.
for row in array_2d:
for item in row:
print(item)Check Your Understanding: Reading Arrays
1. What does the read loop do?
- It visits each array index.
- It retrieves the element stored at that index.
- It can output or process the retrieved value.
- The same pattern can be repeated for every element.
2. Why are nested loops useful with 2D arrays?
- The outer loop can move through the rows.
- The inner loop can move through the columns/items in a row.
- Together they visit every cell.
- This is a standard way to process a 2D array.
3. What order should a 2D array be read in this Python example?
- Take the first row.
- Read across that row.
- Move to the next row.
- Repeat until all rows have been processed.
Worked Example — 2D Array Examination Question
The source worked example stores TV-watching times for five days and four children in a 2D array calledminsWatched.
| Day / Row | Quinn (0) | Lyla (1) | Harry (2) | Elias (3) |
|---|---|---|---|---|
| Monday (0) | 34 | 67 | 89 | 78 |
| Tuesday (1) | 56 | 43 | 45 | 56 |
| Wednesday (2) | 122 | 23 | 34 | 45 |
| Thursday (3) | 13 | 109 | 23 | 90 |
| Friday (4) | 47 | 100 | 167 | 23 |
The source walks through Elias on Monday: Monday is row 0, Elias is column 3, sominsWatched[0][3] = 78.
Three exam-style accesses
| Question | Python expression | Value |
|---|---|---|
| Lyla on Tuesday | minsWatched[1][1] | 43 |
| Harry on Friday | minsWatched[4][2] | 167 |
| Quinn on Wednesday | minsWatched[2][0] | 122 |
Activity 6A: Find Lyla on Tuesday
Difficulty: Medium • Estimated time: 4 minutes
Using the table, write the Python expression for Lyla's Tuesday value.
minsWatched[1][1]Activity 6B: Find Harry on Friday
Difficulty: Medium • Estimated time: 4 minutes
Using the table, write the Python expression for Harry's Friday value.
minsWatched[4][2]Activity 6C: Find Quinn on Wednesday
Difficulty: Medium • Estimated time: 4 minutes
Using the table, write the Python expression for Quinn's Wednesday value.
minsWatched[2][0]Check Your Understanding: Worked Example
1. What is the row index for Thursday?
- Thursday is the fourth day in the table.
- The table labels Thursday with row index 3.
- Therefore the row index is 3.
- The example uses zero-based row indexes.
2. What is the column index for Harry?
- Quinn is column 0.
- Lyla is column 1.
- Harry is column 2.
- Therefore Harry's column index is 2.
3. What does minsWatched[4][2] represent?
- Row 4 is Friday.
- Column 2 is Harry.
- The selected value is 167.
- Therefore Harry watched 167 minutes on Friday.
Exam Practice — From Accessing to Algorithms
The TED source includes substantial Paper 2-style questions on arrays. They show that arrays are rarely examined in isolation: you may need indexing, loops, selection, input validation, calculations and suitable messages in one program.
Past-paper pattern 1: Weather data
The source scenario stores 24 hourly temperature readings for each of seven days in arrays and asks for validation, daily averages, a weekly average and Celsius-to-Fahrenheit conversion. The answer uses nested loops and arrays.
Past-paper pattern 2: Banking data
The source scenario stores account data in a 2D array, then uses the account ID as an index to access balance, overdraft limit and withdrawal amount. Procedures are used to perform actions.
Exam reminder
- Use the data structures named in the question.
- Use the index order demonstrated by the scenario.
- Use iteration when the task requires repeated access to array elements.
- Add comments when the question asks you to explain the purpose of code.
- Include suitable input/output messages when required.
Activity 7A: Array + loop problem
Difficulty: Medium • Estimated time: 7 minutes
Write pseudocode to input 5 integer values into an array, then output all five values.
DECLARE Values : ARRAY[1:5] OF INTEGER
DECLARE Index : INTEGER
FOR Index ← 1 TO 5
INPUT Values[Index]
NEXT Index
FOR Index ← 1 TO 5
OUTPUT Values[Index]
NEXT IndexActivity 7B: 2D algorithm plan
Difficulty: Medium • Estimated time: 4 minutes
A 2D array stores marks for 3 students across 4 tests. What loop structure would you use to visit every mark?
Check Your Understanding: Exam Practice
1. Why are nested loops commonly used with 2D arrays?
- The first loop can control rows.
- The second loop can control columns.
- Together they visit each cell.
- This supports totals, averages, searches and other repeated operations.
2. Why must the array indexes in an answer match the scenario's order?
- The scenario may define which dimension is first.
- Using a different order selects a different element.
- The source examiner tip explicitly warns that X,Y and Y,X may both be used.
- Following the given example prevents indexing mistakes.
3. What should a good array algorithm do before using an index?
- Make sure the index is within the declared array range.
- Follow the index convention specified by the language or question.
- Use the correct row and column order for 2D arrays.
- Then access or modify the required element.
Common Mistakes to Avoid
| Mistake | What goes wrong | Better habit |
|---|---|---|
| Confusing index with position | Index 0 is the first element in a zero-based example. | Count indexes from the stated starting index. |
| Using the wrong 2D order | You access the wrong cell. | Check whether the question uses row/column or another order. |
| Forgetting the index range | You may access an element that does not exist. | Check lower and upper bounds. |
| Mixing pseudocode and Python indexing | The same-looking access can use different starts. | Use the indexing convention of the language/question. |
| Writing a single access instead of iteration | Only one array element is processed. | Use a loop when every element must be processed. |
| Forgetting nested iteration for 2D data | Some rows/columns are never visited. | Use an outer row loop and inner column loop when appropriate. |
| Changing the wrong element | The assignment may target a different index than intended. | Read the index before writing the new value. |
Check Your Understanding: Mistakes
1. What is the most useful question to ask when reading a 2D index?
- Which row does the first index identify in this question?
- Which column does the second index identify?
- What indexing convention is being used?
- What example in the question confirms the order?
2. Why can a loop be better than writing five separate array accesses?
- It reduces repeated code.
- It can process all elements using one pattern.
- It is easier to change the array size or loop range.
- It demonstrates iteration clearly in an exam answer.
3. What should you check before accessing an array element?
- The index is valid.
- The correct row/column order is being used for a 2D array.
- The array has been declared or initialised appropriately.
- The language's indexing convention is being followed.
Final Revision Checklist
- 1D array:one index, linear structure.
- 2D array:two indexes, table of rows and columns.
- Access:use the correct index to read a value.
- Assignment:write a new value to a specific index.
- Iteration:use loops to process multiple array elements.
- Nested iteration:commonly used to traverse 2D arrays.
- Indexing:do not guess—follow the convention shown in the question.
- Python:the lesson uses lists to demonstrate array ideas and zero-based indexing.
- Cambridge pseudocode:follow the array bounds and indexing style shown in the question.
Array Question Bank
1. A 1D array contains [12, 10, 5, 2, 8]. What is the value at index 4?
Answer / Marking Points
- Index 4 is the fifth element.
- The value is 8.
2. Write Python to change the third element of [1,2,3,4,5] to 99.
Answer / Marking Points
- The third element has index 2 in Python's zero-based indexing.
- Use array[2] = 99.
3. What are the two parts of a 2D index in the lesson's Python example?
Answer / Marking Points
- The first index identifies the row.
- The second index identifies the column.
4. In [[1,2,3],[4,5,6],[7,8,9]], what is array[2][1]?
Answer / Marking Points
- Row 2 is [7,8,9].
- Column 1 is 8.
- Therefore the result is 8.
5. Why can arrays be processed with FOR loops?
Answer / Marking Points
- A loop can visit a sequence of indexes.
- The same operation can then be applied to each element.
- This reduces repeated code.
6. What is nested iteration?
Answer / Marking Points
- It is a loop inside another loop.
- It is useful for 2D arrays.
- The outer loop can handle rows while the inner loop handles columns.
7. What does len(array) return in the Python notes?
Answer / Marking Points
- It returns the number of elements.
- For [1,2,3,4,5], it returns 5.
8. Why must you inspect the example in an exam question before writing a 2D index?
Answer / Marking Points
- The question may use a particular order such as row/column.
- The source warns that X,Y and Y,X can both appear.
- The example tells you how the indexes are interpreted.
9. Write pseudocode to output every element of a 5-element array.
Answer / Marking Points
- Use a FOR loop over the full array range.
- OUTPUT the element at the current index.
10. Explain one difference between the array concept and its Python representation used in these notes.
Answer / Marking Points
- The conceptual array is described as a fixed-size, same-type structure.
- Python uses lists in these examples, which are more flexible and can adapt.
- The lesson uses lists to demonstrate array access and iteration.
Source Resources
The uploaded lesson notes include this array video resource:
Arrays video — Craig'n'DaveThis lesson was built from the uploaded “8.2 Arrays” teaching notes and “Arrays” revision notes.