📁 Paper 1 · 3.2 Programming
3.2.6b 2D Arrays & Structured Data
AQA 8525 · GCSE Computer Science · ~10 min read
Notes
──
Video
──
Worksheet
──
Quiz

2D Arrays — The Concept

A 2D array is an array of arrays — imagine it as a grid or table with rows and columns. Each element is accessed using two indices: [row][column], both zero-indexed.

A 3×3 grid looks like this — indices run from 0:

IndexCol 0Col 1Col 2
Row 0grid[0][0]grid[0][1]grid[0][2]
Row 1grid[1][0]grid[1][1]grid[1][2]
Row 2grid[2][0]grid[2][1]grid[2][2]

Accessing and Updating Elements

// Storing a 3×3 noughts-and-crosses grid board[0][0] ← "X" board[0][1] ← "O" board[0][2] ← "X" board[1][0] ← "O" board[1][1] ← "X" board[1][2] ← "O" OUTPUT board[1][1] // "X" — middle cell // Update top-right corner board[0][2] ← "O"

Traversing with Nested FOR Loops

Use nested FOR loops to visit every element — the outer loop iterates over rows, the inner loop over columns.

// Output all elements of a 4-row, 3-column grid FOR row ← 0 TO 3 FOR col ← 0 TO 2 OUTPUT grid[row][col] ENDFOR ENDFOR

Worked Example — Class Marks

Storing marks for 3 students across 4 subjects (rows = students, cols = subjects):

marks[0][0] ← 78 // Student 1, Subject 1 marks[0][1] ← 85 // Student 1, Subject 2 marks[1][0] ← 90 // Student 2, Subject 1 marks[1][1] ← 72 // Student 2, Subject 2 // Calculate total for student 0 across 4 subjects total ← 0 FOR col ← 0 TO 3 total ← total + marks[0][col] ENDFOR OUTPUT "Total: " + str(total)

Searching a 2D Array

// Find the value 100 in a 4×4 grid found ← False FOR row ← 0 TO 3 FOR col ← 0 TO 3 IF grid[row][col] == 100 THEN found ← True OUTPUT "Found at row " + str(row) + ", col " + str(col) ENDIF ENDFOR ENDFOR

Use Cases for 2D Arrays

ScenarioRows representColumns represent
Class marksStudentsSubject marks
Game boardRow on boardColumn on board
Image (pixel map)Pixel rowPixel column
TimetableDay of weekPeriod/lesson slot
Exam tip: Always write the index as [row][column]. If asked "what is stored at grid[2][1]?", remember row 2 is the third row and column 1 is the second column — both are zero-indexed.
⚠️ Common Mistakes
  • Swapping row and column — grid[row][col] not grid[col][row]
  • Forgetting zero-indexing — a 3×3 grid has indices 0,1,2 not 1,2,3
  • Only one ENDFOR in a nested loop — each FOR needs its own ENDFOR
  • Going off the end of the array — a 4-row grid goes TO 3, not TO 4
Video coming soon

Key points

  • 2D arrays use [row][col] — both zero-indexed
  • Nested FOR loops traverse all elements
  • Outer loop = rows, inner loop = columns
  • Use cases: grids, class marks, pixel maps
Click slide or press arrow keys to navigate
✍️

Worksheet — 3.2.6b 2D Arrays

8 questions · 22 marks

Q1What is a 2D array? How is it different from a 1D array?[2]
✅ Mark scheme
Mark scheme
A 2D array is an array of arrays / a grid structure [1]; it uses two indices [row][col] to access elements, whereas a 1D array uses one index [1].
Q2A 3×4 grid called 'seats' is fully zero-indexed. What is the index of the element in the last row, last column?[2]
✅ Mark scheme
Mark scheme
seats[2][3] [2] — 3 rows (0,1,2) so last row = 2 [1]; 4 columns (0,1,2,3) so last col = 3 [1].
Q3Write pseudo-code to store the value 42 at row 1, column 2 of a 2D array called 'data', then output it.[2]
✅ Mark scheme
Mark scheme
data[1][2] ← 42 [1]; OUTPUT data[1][2] [1].
Q4Write a nested FOR loop to output every element of a 3×3 2D array called 'grid'.[4]
✅ Mark scheme
Mark scheme
FOR row ← 0 TO 2 [1]; FOR col ← 0 TO 2 [1]; OUTPUT grid[row][col] [1]; ENDFOR ENDFOR (both) [1].
Q5Give TWO real-world uses of a 2D array, explaining what the rows and columns represent in each.[4]
✅ Mark scheme
Mark scheme
e.g. Game board — rows and columns of the board [2]; Class marks — rows = students, columns = subject marks [2]. Any reasonable real-world use with rows and columns explained for each [2 marks each].
Q6A 2D array 'scores' has 5 rows (students, 0–4) and 3 columns (subjects, 0–2). Write code to sum all scores for student 2 into a variable 'studentTotal'.[3]
✅ Mark scheme
Mark scheme
studentTotal ← 0 [1]; FOR col ← 0 TO 2 [1]; studentTotal ← studentTotal + scores[2][col] [1]; ENDFOR.
Q7A 4×4 grid is set up with all zeros. Describe what the following code does:
FOR i ← 0 TO 3: grid[i][i] ← 1: ENDFOR
[2]
✅ Mark scheme
Mark scheme
It sets the diagonal elements to 1 [1] — grid[0][0], grid[1][1], grid[2][2], grid[3][3] (where row equals column) [1].
Q8What is the total number of elements in a 6-row, 5-column 2D array? How many FOR loop iterations are needed to visit all of them using nested loops?[3]
✅ Mark scheme
Mark scheme
6 × 5 = 30 elements [1]; 30 total iterations [1]; outer loop runs 6 times, inner loop runs 5 times per outer iteration [1].
Check your answers above.
Topic Quiz
Q 1 of 10
You scored
out of 10
Card 1 of 5
Click to flip
🎉
All done!
TermDefinition
🎯

Mini Test — 3.2.6b 2D Arrays

Timed exam conditions.

  • 8 questions · 10 minutes
  • 5 MCQ + 3 short answer
← 3.2.6a Records
17 of 57 · AQA 8525
3.2.7/9 File Handling →