GCSE · Computer Science · AQA · Spec 8525
Two-dimensional arrays
A mark book has a row for each student and a column for each test. A two-dimensional array stores data exactly like that, and finds any value with two numbers.
Computer Science · Data structures
Watch two loops walk through a table
scores holds two students' marks in three quizzes. Row 0 is Asha, row 1 is Ben; columns 0, 1 and 2 are the three quizzes. In this lesson the row index comes first and both indices count from 0.
Before each click, predict: which cell will scores[row][col] point at next?
1 scores ← [[7, 4, 9],2 [5, 8, 6]]3 total ← 04 FOR row ← 0 TO 15 FOR col ← 0 TO 26 total ← total + scores[row][col]7 ENDFOR8 ENDFOR9 OUTPUT total
| row | col | scores[row][col] | total |
|---|---|---|---|
| 0 |
Output
Step 1: Picture scores as a table: row 0 holds Asha's quiz marks (7, 4, 9) and row 1 holds Ben's (5, 8, 6). Before any loop runs, total starts at 0.
Keep your eye on col: it climbs 0, 1, 2 — then snaps back to 0 the moment row moves on.
Predict, then check
Same rule as the trace: the row index comes first, and both indices count from 0.
marks holds three students' results in four tests — one row per student, one column per test. Row 0: 12, 15, 9, 18 · Row 1: 14, 11, 17, 10 · Row 2: 16, 13, 8, 19. What does marks[2][1] give?
Computer Science · Data structures
One index or two?
Sort each data set: to point at one value, do you need one number or two?
Still to sort
One-dimensional array (0)
A single list: one index finds any value.
Where the line is: If one thing tells you which value you mean — which pupil, which day — one index is enough.
Two-dimensional array (0)
A table: a row index and a column index find any value.
Where the line is: If it takes two things to say which value you mean — which student AND which test — the data forms a table.
An array is a data structure that keeps many values of the same data type together under one name. A one-dimensional array is a single list; a two-dimensional array is a table of rows and columns.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
What you need to know
- An array is a data structure that stores a collection of values of the same data type under one identifier.
- A two-dimensional array arranges its elements in rows and columns, like a table. You can think of it as an array of rows, each row the same length.
- Every element is found with two indices, one for the row and one for the column: scores[1][2]. Here the row comes first and both count from 0 — always check the convention you're given.
- Nested loops process every element: the outer loop steps through the rows and, for each row, the inner loop steps through every column.
The big picture
A two-dimensional array stores values of one data type in rows and columns under a single name, like a table. Each element is identified by two indices, one for its row and one for its column, so scores[1][2] means row 1, column 2 (in this lesson the row comes first and both count from 0). To process every element, use nested loops: the outer loop steps through the rows and, for each row, the inner loop steps through every column.
Key points
Worked example
Problem
marks holds four test results for each of three students: one row per student, one column per test, both counted from 0. marks ← [[12, 15, 9, 18], [14, 11, 17, 10], [16, 13, 8, 19]]. Write an algorithm that outputs the third student's total, and work out what it outputs.
⚠ Watch out
Counting from 1 when the array counts from 0. In a grid indexed from 0, the first value in the third row is scores[2][0], not scores[3][1]. Check the convention — which index comes first, and whether counting starts at 0 or 1 — before you read or write any element.
Memory hook
Read it like a theatre ticket: find your ROW first, then walk ALONG to your seat. name[row][column] — row, then along.
Check yourself
Without scrolling up: grid ← [[2, 9], [7, 4], [5, 1]], indexed from 0 with the row first. What is grid[2][0]? And which statement changes the 4 into a 6?
Flashcards
(11)What is an array?
What is a two-dimensional array?
How many indices pick out one element of a 2D array?
Thinking of scores as an array of rows, what does scores[1] on its own give?
How do you change one element of a 2D array?
Which pattern visits every element of a 2D array?
In a row-by-row traversal, what happens to the column index when the row index moves on?
How many times does the inner loop body run for a grid of R rows and C columns?
To total one column, which index stays fixed?
When is a 2D array a better choice than a 1D array?
Counting from 0 with the row first, what are the indices of the last element in a 3-row, 4-column array?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 30 September 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.