GCSE · Computer Science · AQA · Spec 8525
Two-dimensional arrays
A mark book has a row per student and a column per test. Want one mark? You need two numbers. That's a two-dimensional array.
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, call it: 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 is Asha's quiz marks (7, 4, 9), row 1 is Ben's (5, 8, 6). Nothing's been added yet, so total starts at 0.
Keep your eye on col. It climbs 0, 1, 2 — then snaps back to 0 the moment row moves on.
Call it, 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: a collection of values of the same data type, stored under one identifier.
- A two-dimensional array sets those values out in rows and columns, like a table.
- Think of it as an array of rows, where every row is the same length.
- Every element has two indices, one for its row and one for its column — like scores[1][2].
- Here the row comes first and both count from 0. Other places may differ, so always check the convention.
Have a goYour mate Jo is sure the 14 in marks ← [[12, 15], [14, 11]] lives at marks[1][2]. Row first, counting from 0 — where does it really live?
marks[1][0]
14 sits in the second row (row 1) but the first column (column 0). Jo got the row right, then counted the column from 1 — and there's no column 2 here at all.
- Changing a value works the same way: grid[0][1] ← 5 replaces just that one element.
- Choose a 2D array when the data naturally forms a table — a game board, a seating plan, class test scores.
Have a goA shop records how many of each of its 5 products it sells on each of 7 days. One index or two?
Two — one for the product, one for the day.
To point at one sales figure you must say which product AND which day, so the data forms a table. One index alone can't tell you which number you mean.
- Nested loops visit every element: the outer loop steps through the rows, the inner loop sweeps each row's columns.
- The inner loop runs in full for every row, so R rows and C columns means R × C visits.
Have a goA chessboard is stored as 8 rows by 8 columns. Sam reckons a nested loop over it visits 16 squares. How many does it really visit?
64
The inner loop sweeps all 8 columns for each of the 8 rows: 8 × 8 = 64. Sam added the loops (8 + 8) instead of multiplying them.
- Fix the row and loop the columns for a row total; fix the column and loop the rows for a column total.
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 has 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. It feels natural — but indexed from 0, the first value in the third row is scores[2][0], not scores[3][1]. Before touching any element, check: which index comes first, and does counting start at 0 or 1?
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 28 October 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.