0984

Arrays

Programming · 4 question types

Exam Frequency Analysis

Past paper frequency (2018 to 2024)

This topic accounts for approximately 5% of your exam marks.

stable
Rare
Stable5%

1D array manipulation with FOR loops appears regularly in Paper 2. 4 to 6 marks.

A parent records the minutes of TV watched by 4 children (Quinn, Lyla, Harry, Elias) over 5 weekdays (Monday to Friday). The data is held in a 2D array called MinsWatched indexed as [Day, Child], where days 1 to 5 are Monday to Friday and children 1 to 4 are Quinn, Lyla, Harry and Elias.

1 (Quinn)2 (Lyla)3 (Harry)4 (Elias)
1 Monday34678978
2 Tuesday56434556
3 Wednesday122233445
4 Thursday131092390
5 Friday4710016723

Reading a single element uses the row-then-column order:

  • Lyla on Tuesday: OUTPUT MinsWatched[2, 2] outputs 43.
  • Harry on Friday: OUTPUT MinsWatched[5, 3] outputs 167.
  • Quinn on Wednesday: OUTPUT MinsWatched[3, 1] outputs 122.

Calculating each child's weekly total

FOR Child ← 1 TO 4
   ChildTotal ← 0
   FOR Day ← 1 TO 5
      ChildTotal ← ChildTotal + MinsWatched[Day, Child]
   NEXT Day
   OUTPUT "Child ", Child, ": ", ChildTotal, " minutes"
NEXT Child

For Quinn (Child 1): 34 + 56 + 122 + 13 + 47 = 272 minutes.

Finding the day with the most total viewing

DECLARE MaxTotal : INTEGER
DECLARE MaxDay : INTEGER
MaxTotal ← 0
MaxDay ← 0

FOR Day ← 1 TO 5
   DayTotal ← 0
   FOR Child ← 1 TO 4
      DayTotal ← DayTotal + MinsWatched[Day, Child]
   NEXT Child
   IF DayTotal > MaxTotal
     THEN
        MaxTotal ← DayTotal
        MaxDay ← Day
   ENDIF
NEXT Day

OUTPUT "Highest day was ", MaxDay, " with ", MaxTotal, " minutes total"