Signed up recently but had issues with the confirmation email?

Click Forgot password and follow the reset steps. You can choose the same password you used when you signed up. This should then provide access.

Remember to check Spam and Junk. The email will be from auth@progressbytes.co.uk.

Revision notesQuestionsFor schools
Revise Computing
Log inStart revising free
Revision notesQuestionsFor schoolsLog in
GCSE Computer Science/Paper 2/Additional Programming Techniques

two-dimensional arrays(2D)

The use of arrays (or equivalent) when solving problems: two-dimensional arrays(2D)

2.2.3 Additional Programming Techniques

Practise exam questions

Additional Programming Techniques — Note 7 of 13

Use of 2D arrays to emulate database tables of a collection of fields, and records

What you need to know

A two-dimensional (2D) array is an array of arrays, like a table or grid with rows and columns. You access elements using two indices: the first selects the row and the second selects the column. 2D arrays can be used to emulate database tables where each row is a record and each column is a field.

What to know

  • A 2D array is an array of arrays, like a grid or table.
  • Access elements using two indices: array[row, column] (OCR ERL) or array[row][column] (Python).
  • The first index selects the row (sub-array); the second selects the item within that row.
  • An index outside the array causes an error. In array seats[3, 4] the rows are 0 to 2 and the columns 0 to 3, so seats[3, 0] and seats[0, 4] don't exist.
  • In OCR pseudocode: journeys[3,1] = "3.5" (row 3, column 1).
  • 2D arrays can emulate database tables: rows = records, columns = fields.
  • Every element of an array has the SAME data type. If numbers are held in a string array, cast them with int() or float() before you use them in a calculation.
  • Nested FOR loops are used to iterate through all elements of a 2D array.
  • scores[row][column]: the first index picks the row (the week), the second picks the column (the day). scores[1][2] is week 2, Wednesday.
  • ![1D array indexes from 0, and a 2D array where scores[1][2] is week 2, Wednesday](/knowledge/unit-2-knowledge-images/arrays-1d-2d.svg)
  • Whole Array: set the total BEFORE both loops, then add every element inside the inner loop.
  • Per Row: outer loop over the rows; reset the total INSIDE the outer loop (before the inner loop); inner loop over the columns; output the result after the inner loop.
  • Per Column: swap the loops. The outer loop goes over the columns and the inner loop goes over the rows.

Code examples

2D array operations
python
# 2D array (list of lists in Python)
seating = [
    ["pupil1", "pupil2"],
    ["pupil3", "pupil4"]
]

print(seating[0][1])  # "pupil2" (row 0, col 1)
print(seating[1][0])  # "pupil3" (row 1, col 0)

# Loop through all elements
for row in range(len(seating)):
    for col in range(len(seating[row])):
        print(seating[row][col], end=" ")
    print()  # New line after each row
2D array: 4 weeks × 5 weekdays (OCR Exam Reference Language)
text
// Each row is a week; each column is a day (0 = Monday ... 4 = Friday)
array scores[4, 5]
scores[1, 2] = 9           // week 2 (row 1), Wednesday (column 2)
// ... the other 19 scores are stored the same way
print(scores[1, 2])        // 9

// Every score: outer loop = weeks (rows), inner loop = days (columns)
for i = 0 to 3
    for j = 0 to 4
        print("Week " + str(i + 1) + " Day " + str(j) + " Score: " + str(scores[i, j]))
    next j
next i
2D array: 4 weeks × 5 weekdays
python
# Each row is a week; each column is a day (0 = Monday ... 4 = Friday)
scores = [
    [4, 7, 8, 6, 5],    # Week 1
    [6, 5, 9, 4, 3],    # Week 2
    [10, 3, 6, 7, 2],   # Week 3
    [7, 8, 5, 6, 9]     # Week 4
]

# Week 2 (row 1), Wednesday (column 2)
print(scores[1][2])     # 9

# Every score: outer loop = weeks, inner loop = days
for i in range(4):
    for j in range(5):
        print("Week", i + 1, "Day", j, "Score:", scores[i][j])
Total and average for the whole array (OCR Exam Reference Language)
text
// uses the scores array above, already filled
total = 0
count = 0

for i = 0 to 3             // each week
    for j = 0 to 4         // each weekday
        total = total + scores[i, j]
        count = count + 1
    next j
next i

average = total / count
print("Monthly total: " + str(total))
print("Monthly average: " + str(average))
Total and average for the whole array
python
# uses the scores array defined above
total = 0
count = 0

for i in range(4):          # each week
    for j in range(5):      # each weekday
        total += scores[i][j]
        count += 1

average = total / count
print("Monthly total:", total)
print("Monthly average:", average)
Total and average per row (OCR Exam Reference Language)
text
// uses the scores array above
for i = 0 to 3                 // for each week (row)
    weekTotal = 0              // reset for EVERY week
    for j = 0 to 4             // for each day in that week
        weekTotal = weekTotal + scores[i, j]
    next j
    weekAverage = weekTotal / 5
    print("Week " + str(i + 1) + " Total: " + str(weekTotal) + " Average: " + str(weekAverage))
next i
Total and average per row (each week)
python
# uses the scores array defined above
for i in range(4):              # for each week (row)
    week_total = 0              # reset for EVERY week
    for j in range(5):          # for each day in that week
        week_total += scores[i][j]

    week_average = week_total / 5
    print("Week", i + 1, "Total:", week_total, "Average:", week_average)
Total and average per column (OCR Exam Reference Language)
text
// uses the scores array above
for j = 0 to 4                 // for each day (column)
    dayTotal = 0               // reset for EVERY day
    for i = 0 to 3             // for each week
        dayTotal = dayTotal + scores[i, j]
    next i
    dayAverage = dayTotal / 4
    print("Day " + str(j) + " (0 = Mon) Total: " + str(dayTotal) + " Average: " + str(dayAverage))
next j
Total and average per column (each day)
python
# uses the scores array defined above
for j in range(5):              # for each day (column)
    day_total = 0               # reset for EVERY day
    for i in range(4):          # for each week
        day_total += scores[i][j]

    day_average = day_total / 4
    print("Day", j, "(0 = Mon) Total:", day_total, "Average:", day_average)

Exam technique

  • Tip:Use the index order the question sets out (which index is the row and which is the column) and stick to it. Either order is credited if you use it CONSISTENTLY.
  • Tip:When working with a 2D string array, remember to CAST values to numbers before calculations: total = total + float(prices[i, 2]).
  • Mistake:For a total per row, setting the total before BOTH loops means it never resets, so each row's total includes all the rows before it.
  • Example:To total the parcels carried by one van from a 2D string array deliveries (20 rows; column 1 holds the van, column 3 the number of parcels): for i = 0 to 19, if deliveries[i, 1] == van then total = total + int(deliveries[i, 3]), endif, next i, then output total AFTER the loop. Compare one field, then add a DIFFERENT field, cast to a number.

Ready to test yourself?

Practise 2.2.3 questions
← Previous noteone-dimensional (1D)2.2.3 Additional Programming TechniquesNext note →Sub programs (functions and procedures) to produce structured code2.2.3 Additional Programming Techniques

Back to Additional Programming Techniques

Revise another OCR GCSE topic: Programming Fundamentals

Additional Programming Techniques

Note 7 of 13

  1. 1Concatenation
  2. 2slicing
  3. 3ASCII Conversion
  4. 4Open, Read, Write, Close
  5. 5Records to store data
  6. 6SQL to search for data
  7. 7one-dimensional (1D)
  8. 8two-dimensional arrays(2D)
  9. 9Sub programs (functions and procedures) to produce structured code
  10. 10local variables
  11. 11global variables
  12. 12arrays
  13. 13Random number generation
Topic overview

© 2026 Revise Computing · revisecomputing.co.uk

Worried about something?Question Bank UpdatesPrivacy noticeTermsContact

Revise Computing is an independent revision resource. It is not affiliated with, or endorsed by, OCR (Oxford Cambridge and RSA Examinations).