A

8.2 Arrays

1D and 2D arrays • indexing • accessing and modifying elements • iteration

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.

Core idea:The index tells the programwhich boxto access. The source visual shows five elements at indexes 0, 1, 2, 3 and 4.
Index01234
ValueBEADS

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.

Python
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)     # 5

Accessing usesarray[index]. Modifying usesarray[index] = newValue. Python useslen(array)to obtain the length in the examples.

Cambridge IGCSE pseudocode

Pseudocode examples
DECLARE scores : ARRAY[0:4] OF INTEGER
scores ← [12, 10, 5, 2, 8]

colours[4] ← "Red"    // index 4 is the 5th element

The 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.

Selected: index 0 → 12

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?

2.Index 3 refers to the fourth element.

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.

Answer
scores[2] = 99

Check Your Understanding: 1D Arrays

  • 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.
  • 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.
  • 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.
  • 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.

Memory trick:1D = one index. 2D = two indexes. Think[row][column].
Column 0Column 1Column 2
Row 0123
Row 1456
Row 2789

For example,array_2d[1][2]selects row 1, column 2 →6in the Python example.

Python example

Python
array_2d = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
]

print(array_2d[0][0])  # 1
print(array_2d[1][2])  # 6

A 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

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 Charlie

The 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.

Selected: row 0, column 0 → 1

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.

Answer: row 2, column 1 → 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?

Row 1, column 0→ value4.

Check Your Understanding: 2D Arrays

  • It has two dimensions.
  • One index identifies the row.
  • The second index identifies the column.
  • Both are needed to identify one cell.
  • 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.
  • As a table.
  • Rows are one dimension.
  • Columns are the other dimension.
  • Each cell stores one array element.
  • 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.

array[index]

2D

Two indexes identify row + column in the source example.

array[row][column]

Zero-based versus one-based indexing

ContextFirst element exampleImportant point
Python examples in the sourceindex 0Python indexing begins at 0 in the examples.
Cambridge pseudocode examplesARRAY[1:30] / ARRAY[1:3,1:3]The pseudocode examples can use ranges starting at 1.
Exam questionFollow the given exampleDo not assume the order or starting index; use the convention shown in the question.
Exam habit:Before writing an answer, look at the question's sample access. It tells you whether the first index is the row or column, and it shows the indexing convention being used.

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

  • 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.
  • 0
  • 1
  • 2
  • 3
  • 4
  • 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.

Cambridge pseudocode
DECLARE myArray[5] : INTEGER
DECLARE index : INTEGER

FOR index FROM 1 TO 5
    myArray[index] ← index * 10
NEXT index

This creates the sequence 10, 20, 30, 40 and 50 when the pseudocode index runs from 1 to 5.

Python equivalent

Python
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.

Answer
FOR index FROM 1 TO 5
    myArray[index] ← index * 5
NEXT index

Activity 4B: Trace one iteration

Difficulty: Easy • Estimated time: 3 minutes

What value is stored when index = 4 in myArray[index] ← index * 10?

40, because 4 × 10 = 40.

Check Your Understanding: Writing Arrays

  • 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.
  • 10
  • 20
  • 30
  • 40
  • 50
  • 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.

Cambridge pseudocode
FOR index FROM 1 TO 5
    OUTPUT "Value at index " + index + ": " + myArray[index]
NEXT index
Python
for 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.

Python: nested iteration through a 2D array
for row in array_2d:
    for item in row:
        print(item, end=" ")
    print()
Think of it as scanning:1D → move along one row. 2D → scan each row, then each column inside that row.

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.

Answer
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.

Answer
for row in array_2d:
    for item in row:
        print(item)

Check Your Understanding: Reading Arrays

  • 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.
  • 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.
  • 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 / RowQuinn (0)Lyla (1)Harry (2)Elias (3)
Monday (0)34678978
Tuesday (1)56434556
Wednesday (2)122233445
Thursday (3)131092390
Friday (4)4710016723

The source walks through Elias on Monday: Monday is row 0, Elias is column 3, sominsWatched[0][3] = 78.

Three exam-style accesses

QuestionPython expressionValue
Lyla on TuesdayminsWatched[1][1]43
Harry on FridayminsWatched[4][2]167
Quinn on WednesdayminsWatched[2][0]122
Exam method:identify the row first → identify the column → write the two indexes in the order used by the question → check the selected cell.

Activity 6A: Find Lyla on Tuesday

Difficulty: Medium • Estimated time: 4 minutes

Using the table, write the Python expression for Lyla's Tuesday value.

Answer → 43
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.

Answer → 167
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.

Answer → 122
minsWatched[2][0]

Check Your Understanding: Worked Example

  • 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.
  • Quinn is column 0.
  • Lyla is column 1.
  • Harry is column 2.
  • Therefore Harry's column index is 2.
  • 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.

Model answer
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 Index

Activity 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?

Nested iteration:an outer loop for the 3 students/rows and an inner loop for the 4 tests/columns.

Check Your Understanding: Exam Practice

  • 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.
  • 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.
  • 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

MistakeWhat goes wrongBetter habit
Confusing index with positionIndex 0 is the first element in a zero-based example.Count indexes from the stated starting index.
Using the wrong 2D orderYou access the wrong cell.Check whether the question uses row/column or another order.
Forgetting the index rangeYou may access an element that does not exist.Check lower and upper bounds.
Mixing pseudocode and Python indexingThe same-looking access can use different starts.Use the indexing convention of the language/question.
Writing a single access instead of iterationOnly one array element is processed.Use a loop when every element must be processed.
Forgetting nested iteration for 2D dataSome rows/columns are never visited.Use an outer row loop and inner column loop when appropriate.
Changing the wrong elementThe assignment may target a different index than intended.Read the index before writing the new value.
Teacher tip for students:When you seearray[?], ask “Which box?” When you seearray[?][?], ask “Which row, then which column?”

Check Your Understanding: Mistakes

  • 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?
  • 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.
  • 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

Answer / Marking Points
  • Index 4 is the fifth element.
  • The value is 8.
Answer / Marking Points
  • The third element has index 2 in Python's zero-based indexing.
  • Use array[2] = 99.
Answer / Marking Points
  • The first index identifies the row.
  • The second index identifies the column.
Answer / Marking Points
  • Row 2 is [7,8,9].
  • Column 1 is 8.
  • Therefore the result is 8.
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.
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.
Answer / Marking Points
  • It returns the number of elements.
  • For [1,2,3,4,5], it returns 5.
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.
Answer / Marking Points
  • Use a FOR loop over the full array range.
  • OUTPUT the element at the current index.
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'Dave

This lesson was built from the uploaded “8.2 Arrays” teaching notes and “Arrays” revision notes.