SLIDE 1 / 10
CSZone.co.uk
Click anywhere to advance · Arrow keys also work
AQA 7517 · Paper 1 · 4.2.1

Arrays
1D & 2D

AQA A-Level Computer Science · Section 4.2 Fundamentals of Data Structures

WHAT YOU'LL LEARN
1D arrays · 2D arrays · Indexing · Operations · Static vs dynamic
AQA SPEC LINK
4.2.1 — Arrays and their uses in programming
1D Arrays

One-Dimensional Arrays

An array is a fixed-size, ordered collection of elements of the same data type stored in contiguous memory, accessed by index.
scores ← [72, 85, 91, 64, 78]
7285916478
[0][1][2][3][4]
scores[0] → 72    scores[2] → 91    scores[4] → 78
AQA Pseudocode

Declaring & Using 1D Arrays

scores ← [0, 0, 0, 0, 0]    ← declare array of 5 integers

FOR i ← 0 TO 4
  scores[i] ← INT(USERINPUT)
ENDFOR

total ← 0
FOR i ← 0 TO 4
  total ← total + scores[i]
ENDFOR
OUTPUT "Average: " + STR(total / 5)
2D Arrays

Two-Dimensional Arrays

A 2D array is an array of arrays — think of it as a grid with rows and columns. Accessed with TWO indices: array[row][col]
grid ← [[1,2,3],[4,5,6],[7,8,9]]   ← 3×3 grid

grid[0][0] → 1   grid[1][2] → 6   grid[2][1] → 8
Uses: game boards (chess, noughts & crosses), images (pixel grids), spreadsheet data, seating plans
2D Array Operations

Nested Loops for 2D Arrays

PRINT A 3×3 GRID
FOR row ← 0 TO 2
  FOR col ← 0 TO 2
    OUTPUT grid[row][col]
  ENDFOR
ENDFOR
Outer loop controls rows, inner loop controls columns. For an m×n array: m × n = total elements.
Static vs Dynamic

Array Types

STATIC ARRAY
Fixed size set at declaration
Cannot grow or shrink at runtime
Memory allocated at compile time
DYNAMIC ARRAY / LIST
Can grow or shrink during runtime
Python lists are dynamic
More flexible; slightly more overhead
AQA considers arrays as static. Use lists (Section 4.2.2) when dynamic behaviour is needed.
Common Operations

Array Operations in AQA

OperationAQA PseudocodeDescription
Accessscores[i]Get element at index i
Updatescores[i] ← 95Set element at index i
LengthLEN(scores)Number of elements
TraverseFOR i ← 0 TO LEN-1Visit each element
SearchLinear or binary searchFind a specific value
SortBubble/merge/quickReorder elements
Linear Search

Searching a 1D Array

SUBROUTINE linearSearch(arr, target)
  FOR i ← 0 TO LEN(arr)-1
    IF arr[i] = target THEN
      RETURN i           ← return index
    ENDIF
  ENDFOR
  RETURN -1            ← not found
ENDSUBROUTINE
Linear search checks each element in order — O(n) time complexity. Returns the index or -1 if not found.
AQA Exam Style

Practice Question

AQA 7517 — Paper 1 Style
An array temps stores daily temperatures: [12, 18, 15, 22, 19, 14, 16]

Write pseudocode to find and output the highest temperature in the array.
[4 marks]
highest ← temps[0]
FOR i ← 1 TO LEN(temps)-1
  IF temps[i] > highest THEN
    highest ← temps[i]
  ENDIF
ENDFOR
OUTPUT "Highest: " + STR(highest)
Summary

Key Points to Remember

Array: fixed-size, ordered, same data type, contiguous memory
1D: single index arr[i]; 2D: two indices arr[row][col]
Arrays are zero-indexed in AQA pseudocode (index 0 to length-1)
Use FOR loops to traverse; nested FOR loops for 2D arrays
Static size set at declaration — cannot change during runtime
🎉 Lesson complete — move to the quiz!