Revision Library

1D and 2D Array Processing: Writing and Tracing Programs - Worksheets, Questions and Revision

20 original exam-style questions - 9 pages of questions with a full mark scheme - free printable PDF.

Download PDFJump to mark scheme (page 10)Read the revision guide
« Previous: Translators and Integrated Development Environments (IDEs)
Revision Library
revisionlibrary.co.uk
GCSE · Computer Science

P2.11 1D and 2D Array Processing: Writing and Tracing Programs

OCR J277 · Calculators not allowed · about 100 minutes
Total Marks
Name: _______________________________    Date: ____ / ____ / ______
Answer ALL questions. Show all your working.
1
A gym class records the number of press-ups completed by 5 students in a 1D array called pressUps, indexed from 0: pressUps = [12, 20, 8, 15, 17]
(a)State the value stored at pressUps[0].(1)
(b)State the index of the element that holds the value 15.(1)
(c)State the number of elements in the array pressUps.(1)
(Total for Question 1 is 3 marks)
2
Explain why it is more efficient for a program to store the press-up totals for a whole class in a single array, rather than in 30 separate variables.
(Total for Question 2 is 3 marks)
3
The pseudocode below is intended to input 5 scores from the keyboard into a 1D array called scores, but two lines are missing.
scores <- [0, 0, 0, 0, 0]
FOR index <- 0 TO 4
    ____________________
NEXT index
(Total for Question 3 is 2 marks)
4
The array temperatures stores 7 daily temperature readings (in degrees Celsius) for one week: temperatures = [14, 17, 12, 19, 21, 16, 13]
The pseudocode below is intended to calculate the total of all 7 temperatures.
total <- 0
FOR day <- 0 TO 6
    total <- total + temperatures[day]
NEXT day
OUTPUT total
(a)State the value that will be output by this algorithm.(2)
(b)Extend the algorithm to also calculate and output the mean (average) temperature for the week, to 1 decimal place.(2)
(Total for Question 4 is 4 marks)
5
The array attendance stores the number of pupils absent from school each day over 6 days: attendance = [3, 0, 5, 2, 0, 1]
(a)Write pseudocode to count how many of the 6 days had zero pupils absent (attendance[index] = 0), storing the result in a variable called perfectDays.(3)
(b)State the value that perfectDays will hold after your algorithm in part (a) has run.(1)
(Total for Question 5 is 4 marks)
6
The array windSpeeds holds 6 wind speed readings, in mph: windSpeeds = [18, 25, 9, 31, 14, 22]
Write pseudocode to find the highest wind speed in the array, storing it in a variable called strongest.
(Total for Question 6 is 4 marks)
7
The pseudocode below contains one error, which stops it correctly finding the lowest value in the array readings, where readings = [40, 12, 27, 8, 19]:
lowest <- readings[0]
FOR index <- 0 TO 4
    IF readings[index] < lowest THEN
        lowest <- index
    ENDIF
NEXT index
OUTPUT lowest
(a)Identify the line that contains the error, and explain what is wrong with it.(2)
(b)Write the corrected line of pseudocode.(1)
(Total for Question 7 is 3 marks)
8
The pseudocode below reverses the order of the values in a 5 element array called letters, in place (without using a second array).
letters <- ["P", "L", "A", "N", "T"]
FOR left <- 0 TO 1
    right <- 4 - left
    temp <- letters[left]
    letters[left] <- letters[right]
    letters[right] <- temp
NEXT left
OUTPUT letters
(a)Complete the trace table below to show the value of letters after each pass of the loop.
leftrightletters
(start)-[P,L,A,N,T]
0
1
(3)
(b)Explain why the FOR loop only needs to run from 0 TO 1, rather than looping through every index in the array.(2)
(Total for Question 8 is 5 marks)
9
A cinema stores the number of seats booked for 3 screens over 4 showings each in a 2D array called bookings, where the first index is the screen number (0 to 2) and the second index is the showing number (0 to 3):
bookings = [[45, 60, 38, 50], [22, 40, 55, 30], [70, 65, 80, 60]]
(a)State the value of bookings[1][2], and explain what it represents.(2)
(b)State the total number of individual booking values stored in the whole 2D array, and explain how you calculated it.(2)
(Total for Question 9 is 4 marks)
10
Using the bookings array from question 9, write pseudocode using nested FOR loops to calculate the total number of seats booked across all 3 screens and all 4 showings, storing the result in a variable called grandTotal.
(Total for Question 10 is 5 marks)
11
Using the bookings array from question 9, write pseudocode to calculate the total number of seats booked for screen 0 only (i.e. the total of just one row of the 2D array), storing the result in a variable called screenTotal.
(Total for Question 11 is 3 marks)
12
Explain the difference between accessing a single element of a 1D array and a single element of a 2D array.
(Total for Question 12 is 2 marks)
13
A weather station records rainfall, in mm, for 3 towns over 5 days in a 2D array called rainfall, where the first index is the town number (0 to 2) and the second index is the day number (0 to 4):
rainfall = [[2, 0, 5, 8, 1], [0, 0, 3, 4, 2], [6, 4, 7, 5, 3]]
Describe, using structured English or pseudocode, an algorithm to find which town (index 0, 1 or 2) had the highest total rainfall across the 5 days, and state the total for that town.
(Total for Question 13 is 6 marks)
14
The array visits stores the number of visitors to a museum over 3 sensors across 4 days: visits = [[120, 95, 0, 140], [80, 0, 60, 110], [0, 75, 90, 0]]
Write pseudocode using nested FOR loops to count how many of the 12 values in the array are equal to 0 (representing a day a sensor recorded no visitors), storing the result in a variable called zeroCount.
(Total for Question 14 is 5 marks)
15
A tutor records monthly expenses, in pounds, for 3 categories over 4 months in a 2D array called expenses, where the first index is the category (0 to 2) and the second index is the month (0 to 3):
expenses = [[80, 95, 70, 105], [40, 45, 38, 42], [120, 110, 130, 140]]
Write a complete pseudocode algorithm that calculates the average monthly expense for each category (i.e. each row's total divided by 4), and stores the three results in a new 1D array called averages.
(Total for Question 15 is 8 marks)
16
The array prices holds the price, in pounds, of 4 items in a shop: prices = [20, 35, 12, 48]
Write pseudocode to apply a 10% discount to every price in the array (i.e. reduce each value by 10%), updating the array in place.
(Total for Question 16 is 3 marks)
17
A register2D array stores whether each of 4 students attended each of 5 lessons (1 = present, 0 = absent), where the first index is the student and the second index is the lesson:
register2D = [[1, 1, 0, 1, 1], [1, 0, 0, 1, 0], [0, 0, 0, 0, 1], [1, 1, 1, 1, 1]]
A variable studentIndex already holds the row index of one particular student. Write pseudocode to count how many of the 5 lessons that one student attended, storing the result in a variable called lessonsAttended.
(Total for Question 17 is 4 marks)
18
State one advantage of using a single 2D array, rather than several separate 1D arrays, to store a grid of related data such as a seating plan.
(Total for Question 18 is 2 marks)
19
The array answers stores a student's answers to a 5 question multiple-choice quiz: answers = ["A", "C", "B", "A", "D"]
Write pseudocode to count how many of the 5 answers are "A", storing the result in a variable called countA.
(Total for Question 19 is 3 marks)
20
The array percentages stores 6 exam percentages: percentages = [64, 88, 51, 73, 95, 68]
Write pseudocode to find both the highest and the lowest values in the array in a single pass through it, storing them in variables called highest and lowest.
(Total for Question 20 is 5 marks)
Mark scheme · P2.11 1D and 2D Array Processing: Writing and Tracing Programs

Question 1

Question 2

Question 3

Question 4

Question 5

Question 6

Question 7

Question 8

Question 9

Question 10

Question 11

Question 12

Question 13

Question 14

Question 15

Question 16

Question 17

Question 18

Question 19

Question 20

Mark your answers

This checks your answers in your browser, stores nothing on a server and needs no account.

Question 1

3 marks
Did your answer earn the marks?

Question 2

3 marks
Did your answer earn the marks?

Question 3

2 marks
Did your answer earn the marks?

Question 4

4 marks
Did your answer earn the marks?

Question 5

4 marks
Did your answer earn the marks?

Question 6

4 marks
Did your answer earn the marks?

Question 7

3 marks
Did your answer earn the marks?

Question 8

5 marks
Did your answer earn the marks?

Question 9

4 marks
Did your answer earn the marks?

Question 10

5 marks
Did your answer earn the marks?

Question 11

3 marks
Did your answer earn the marks?

Question 12

2 marks
Did your answer earn the marks?

Question 13

6 marks
Did your answer earn the marks?

Question 14

5 marks
Did your answer earn the marks?

Question 15

8 marks
Did your answer earn the marks?

Question 16

3 marks
Did your answer earn the marks?

Question 17

4 marks
Did your answer earn the marks?

Question 18

2 marks
Did your answer earn the marks?

Question 19

3 marks
Did your answer earn the marks?

Question 20

5 marks
Did your answer earn the marks?
Mark my answers