Topic 4 Math Test
Topic 4 Math Test
A car has features that monitor its speed, direction and distance from the car in front. This is shown in Figure 1.
For example, if the car is travelling forward, input B would have a binary representation of 1.
(b) Construct a logic diagram with inputs A, B, and C and output Z to represent the following scenario:
the car is travelling forward AND it is less than 20 metres from the vehicle in front.
OR
the car speed is more than 130 km per hour.
An additional row (input D) is to be added to assist when the car is in reverse or stationary. Input D checks if there are
obstructions less than 3 metres from the rear of the car.
(c) State the rules that need to be added to Figure 1 to test this condition. [2]
Information similar to that presented in Figure 1 could be used to construct decisions and conditions in program
design (see Figure 2).
F=5
S = 30
T = true
(e) Construct an algorithm in pseudocode that repeats the following steps while the car is moving:
Input the value for the distance from the vehicle in front.
Input the value for the speed of the car.
Check the inputs and notify the user if either the distance from the car in front is less than 20
metres or if the speed of the car is more than 130 kilometres per hour.
The algorithm will only terminate when the car stops moving. [6]
The collection RAINBOW holds the names of the main colours of the rainbow along with their order indicator, as
follows:
(b) Construct an algorithm using pseudocode to read the data from RAINBOW and store the names of
the colours in a one-dimensional string array, COLOUR, and the order indicators in another one-
dimensional string array, ORDER.
The matching colour and order indicator must have the same index in the COLOUR and
ORDER arrays. [4]
(c) Construct an algorithm using pseudocode to sort the contents of the array ORDER into alphabetical order.
The indexes for the corresponding data in the two parallel arrays must remain the same after sorting. [5]
(d) Compare and contrast the bubble sort algorithm and the selection sort algorithm. [4]
For example, if the car is travelling forward, input B would have a binary representation of 1.
(b) Construct a logic diagram with inputs A, B, and C and output Z to represent the following scenario:
the car is travelling forward AND it is less than 20 metres from the vehicle in front.
OR
the car speed is more than 130 km per hour.
An additional row (input D) is to be added to assist when the car is in reverse or stationary. Input D checks if there are
obstructions less than 3 metres from the rear of the car.
(c) State the rules that need to be added to Figure 1 to test this condition. [2]
Information similar to that presented in Figure 1 could be used to construct decisions and conditions in program
design (see Figure 2).
(d) Determine the value of the following expression given that the input values for F, S and T are:
F = 40
S = 115
T = true
(e) Construct an algorithm in pseudocode that repeats the following steps while the car is moving:
Input the value for the distance from the vehicle in front.
Input the value for the speed of the car.
Check the inputs and notify the user if either the distance from the car in front is less than 15
metres or if the speed of the car is more than 115 kilometres per hour.
The algorithm will only terminate when the car stops moving. [6]
The collection CAPITALS holds the names of a number of capital cities and the names of their corresponding
countries, as follows:
(b) Construct an algorithm using pseudocode to read the data from CAPITALS and store the names of
the cities in a one-dimensional string array, CITY, and the names of the countries in another one-
dimensional string array, COUNTRY.
The matching city and country must have the same index in the CITY and COUNTRY arrays. [4]
(c) Construct an algorithm using pseudocode to sort the contents of the array COUNTRY into
alphabetical order. The indexes for the corresponding data in the two parallel arrays must remain
the same after sorting. [5]
(d) Compare and contrast the bubble sort algorithm and the selection sort algorithm. [4]
A car has features that monitor its speed, direction and distance from the car in front. This is shown in Figure 1.
the car is travelling forward AND it is less than 20 metres from the vehicle in front.
OR
the car speed is more than 130 km per hour.
An additional row (input D) is to be added to assist when the car is in reverse or stationary. Input D checks if there are
obstructions less than 3 metres from the rear of the car.
(c) State the rules that need to be added to Figure 1 to test this condition. [2]
Information similar to that presented in Figure 1 could be used to construct decisions and conditions in program
design (see Figure 2).
(d) Determine the value of the following expression given that the input values for F, S and T are:
F=5
S = 30
T = true
(e) Construct an algorithm in pseudocode that repeats the following steps while the car is moving:
Input the value for the distance from the vehicle in front.
Input the value for the speed of the car.
Check the inputs and notify the user if either the distance from the car in front is less than 20
metres or if the speed of the car is more than 130 kilometres per hour.
The algorithm will only terminate when the car stops moving. [6]
Strings are zero-indexed: the index of a string’s first character is 0, and the index of a string’s last character is the length
of the string minus 1.
(a) The following section of pseudocode represents an algorithm that is intended to perform validation
to check if the length of the string entered is between 1 and 100, inclusive. The algorithm is incorrect
and contains two errors.
input X
loop while (lenString(X) < 1) AND (lenString(X) > 100)
output "The string’s length is out of range, please try again"
output X
end loop
Construct the correct pseudocode that removes the two errors. [2]
(b) The following algorithm performs a task using the string sub-programs:
J = ""
loop C from 1 to 4
input X
input Y
input Z
R = subString(X, Y, Z)
S = revString(R)
J = joinString(S, J)
end loop
output J
Copy and complete the trace table for the algorithm using the input data:
The values for columns J, C, X, Y and Z for the first row have been done for you.
[5]
An algorithm is required to set new passwords. The new passwords must be at least eight characters in length and
there must be no two consecutive repeated characters.
For example, the password “fEedBack” would be accepted, but the password “FEEDBACK” would fail because of the
two consecutive repeated ‘E’ characters.
Following these checks, the password must be entered a second time to check that the user has entered the
password they intended.
If any of the tests fail, the password is rejected and the whole procedure is repeated to allow a new password to be re-
entered.
An appropriate message must be output to the user at each stage of the algorithm.
For example:
(c) Construct this algorithm in pseudocode, making use of the given string manipulation sub-
programs. [8]
Strings are zero-indexed: the index of a string’s first character is 0, and the index of a string’s last character is the length
of the string minus 1.
(a) The following section of pseudocode represents an algorithm that is intended to perform validation
to check if the length of the string entered is between 10 and 25, inclusive. The algorithm is incorrect
and contains two errors.
input X
loop while (lenString(X) < 10) AND (lenString(X) > 25)
output "The string’s length is out of range, please try again"
output X
end loop
Construct the correct pseudocode that removes the two errors. [2]
(b) The following algorithm performs a task using the string sub-programs:
J = ""
loop C from 1 to 4
input X
input Y
input Z
R = subString(X, Y, Z)
S = revString(R)
J = joinString(S, J)
end loop
output J
Copy and complete the trace table for the algorithm using the input data:
The values for columns J, C, X, Y and Z for the first row have been done for you.
[5]
An algorithm is required to set new passwords. The new passwords must be at least eight characters in length and
there must be no two consecutive repeated characters.
For example, the password “fEedBack” would be accepted, but the password “FEEDBACK” would fail because of the
two consecutive repeated ‘E’ characters.
Following these checks, the password must be entered a second time to check that the user has entered the
password they intended.
If any of the tests fail, the password is rejected and the whole procedure is repeated to allow a new password to be re-
entered.
An appropriate message must be output to the user at each stage of the algorithm.
For example:
(c) Construct this algorithm in pseudocode, making use of the given string manipulation sub-
programs. [8]
8. [Maximum mark: 15]
(a) Define the NOR Boolean operator. [1]
A car has features that monitor its speed, direction and distance from the car in front. This is shown in Figure 1.
For example, if the car is travelling forward, input B would have a binary representation of 1.
(b) Construct a logic diagram with inputs A, B, and C and output Z to represent the following scenario:
the car is travelling forward AND it is less than 20 metres from the vehicle in front.
OR
the car speed is more than 130 km per hour.
An additional row (input D) is to be added to assist when the car is in reverse or stationary. Input D checks if there are
obstructions less than 3 metres from the rear of the car.
(c) State the rules that need to be added to Figure 1 to test this condition. [2]
Information similar to that presented in Figure 1 could be used to construct decisions and conditions in program
design (see Figure 2).
F = 40
S = 115
T = true
(e) Construct an algorithm in pseudocode that repeats the following steps while the car is moving:
Input the value for the distance from the vehicle in front.
Input the value for the speed of the car.
Check the inputs and notify the user if either the distance from the car in front is less than 15
metres or if the speed of the car is more than 115 kilometres per hour.
The algorithm will only terminate when the car stops moving. [6]
9. [Maximum mark: 1]
Define the term constant. [1]
N = 1216
X=0
loop while N > 0
X = X + N mod 10
N = N div 10
end loop
output (X) [4]
Figure 1: Data held in the NAMES array and the SCORES array
(a) State the name of the gymnast whose score is stored in SCORES[5].
[1]
To qualify for the next round of competition, a competitor must have a score above the average score.
(c) Construct an algorithm in pseudocode that will determine and output the number of gymnasts
whose scores are above the average score.
You may assume that the average score is stored in the variable AVERAGE.
[4]
Figure 1: Data held in the NAMES array and the SCORES array
(a) State the name of the gymnast whose score is stored in SCORES[5].
[1]
To qualify for the next round of competition, a competitor must have a score above the average score.
(c) Construct an algorithm in pseudocode that will determine and output the number of gymnasts
whose scores are above the average score.
You may assume that the average score is stored in the variable AVERAGE.
[4]
K=5
A=1
B=0
while K >= 0
if DATA[K] mod 2 < 1
then
A = A * DATA[K]
else
B=B+1
end if
K=K-1
end while
output(A)
output(B)
(a) Construct a trace table for this algorithm. [4]
The room numbers of the students who have paid their bills for the month of May so far are stored in the
ROOMNUMS array (see Figure 1).
For example, the bill for room number 93 has been paid. This can be seen in ROOMNUMS[6].
The campus administrator would like to check whether the student in room number X has paid the bill for the month
of May or not.
The sub-program check(ROOMNUMS) accepts the array ROOMNUMS, allows room number X to be input, searches
for X in the ROOMNUMS array, and outputs an appropriate message.
Figure 2 shows two examples of input and output for the data stored in the ROOMNUMS array as given in Figure 1.
(d) Construct an algorithm in pseudocode to sort the ROOMNUMS array in descending order using the
bubble sort algorithm. [6]
21. [Maximum mark: 2]
Outline what is meant by a collection. [2]
The room numbers of the students who have paid their bills for the month of May so far are stored in the
ROOMNUMS array (see Figure 1).
For example, the bill for room number 93 has been paid. This can be seen in ROOMNUMS[6].
The campus administrator would like to check whether the student in room number X has paid the bill for the month
of May or not.
The sub-program check(ROOMNUMS) accepts the array ROOMNUMS, allows room number X to be input, searches
for X in the ROOMNUMS array, and outputs an appropriate message.
Figure 2 shows two examples of input and output for the data stored in the ROOMNUMS array as given in Figure 1.
(d) Construct an algorithm in pseudocode to sort the ROOMNUMS array in ascending order using the
selection sort algorithm.
[6]
K=0
A=0
B=0
loop while K<6
if DATA[K]>4 and DATA[K]<8
A=A+DATA[K]
B=B+1
end if
K=K+1
end loop
C=A/B
Three dice are thrown, with faces that have numbers from 1 to 6.
The dice are thrown seven times, and the data are stored in a two-dimensional array called DICEDIAL (see Figure 2).
The sub-program DuplicateNum(DICEDIAL,R) checks whether there are repeated numbers in row R. If the numbers
are not repeated, it returns 0, otherwise it returns the repeated number.
The DuplicateNum() sub-program will produce the following from the values used in Figure 2:
DuplicateNum(DICEDIAL,0) returns 2
DuplicateNum(DICEDIAL,2) returns 0
The sub-program lowestRT(DICEDIAL) accepts the DICEDIAL array and outputs the lowest row total and the indexes
of all the rows with that total.
From the example data given in Figure 2, lowestRT(DICEDIAL) would output that the lowest row total is 6, and it
occurs in the rows with indexes 5 and 6.
Three dice are thrown, with faces that have numbers from 1 to 6.
The dice are thrown seven times, and the data are stored in a two-dimensional array called DICEDIAL (see Figure 2).
Figure 2: The example data stored in the DICEDIAL array
(a) Construct an algorithm in pseudocode to calculate the sum of all values stored in the DICEDIAL
array. [3]
The sub-program DuplicateNum(DICEDIAL,R) checks whether there are repeated numbers in row R. If the numbers
are not repeated, it returns 0, otherwise it returns the repeated number.
The DuplicateNum() sub-program will produce the following from the values used in Figure 2:
DuplicateNum(DICEDIAL,0) returns 2
DuplicateNum(DICEDIAL,2) returns 0
The sub-program highestRT(DICEDIAL) accepts the DICEDIAL array and outputs the highest row total and the
indexes of all the rows with that total.
From the example data given in Figure 2, highestRT(DICEDIAL) would output that the highest row total is 16, and it
occurs in the rows with indexes 3 and 4.
K=3
loop while K>=0
A=K mod 3
[4]
output (NAMES[A])
K=K−1
end while
For example:
Every number can be classified as abundant, deficient, or perfect according to the following definitions:
A number is an abundant number if it is less than the sum of its proper divisors. For example, 12 is an abundant
number because 1 + 2 + 3 + 4 + 6 = 16, and 16 > 12.
A number is a deficient number if it is greater than the sum of its proper divisors. For example, 9 is a deficient number
because 1 + 3 = 4, and 4 < 9.
A number is a perfect number if it is equal to the sum of its proper divisors. For example, 28 is a perfect number
because 1 + 2 + 4 + 7 + 14 = 28, and 28 = 28.
(b) Construct an algorithm in pseudocode that will accept an integer, K(K>0), and output whether K is
an abundant number, a deficient number, or a perfect number. [6]
(c) The one-dimensional array DATA holds X(X>0) elements. Each element in the array is an integer
greater than zero.
determine the number of abundant integers in the array DATA that are odd
determine the number of abundant integers in the array DATA that are even
output these two numbers.
For example:
Every number can be classified as abundant, deficient, or perfect according to the following definitions:
A number is an abundant number if it is less than the sum of its proper divisors. For example, 12 is an abundant
number because 1 + 2 + 3 + 4 + 6 = 16, and 16 > 12.
A number is a deficient number if it is greater than the sum of its proper divisors. For example, 9 is a deficient number
because 1 + 3 = 4, and 4 < 9.
A number is a perfect number if it is equal to the sum of its proper divisors. For example, 28 is a perfect number
because 1 + 2 + 4 + 7 + 14 = 28, and 28 = 28.
(b) Construct an algorithm in pseudocode that will accept an integer, K(K>0), and output whether K is
an abundant number, a deficient number, or a perfect number. [6]
(c) The one-dimensional array DATA holds X(X>0) elements. Each element in the array is an integer
greater than zero.
The subprogram isAbundant() is available. It accepts an integer, N, and returns True if N is an
abundant number, otherwise it returns False. For example, isAbundant(17)returns False.
determine the number of abundant integers in the array DATA that are odd
determine the number of abundant integers in the array DATA that are even
output these two numbers.
You can assume that the value of X and the array DATA have already been inputted. [7]
mystery(NAMES, 3)
Show all your working. [4]
For example:
(a) Construct a logic expression that evaluates to True if X is a proper divisor of Y and to False
otherwise. [2]
The subprogram sumPD(N) accepts an integer, N(N>1), and returns the sum of all proper divisors of N. For example,
sumPD(16) returns 15 (1 + 2 + 4 + 8 = 15).
(c) Every number can be classified as abundant, deficient, or perfect according to the following
definitions:
A number is an abundant number if it is less than the sum of its proper divisors. For example, 12 is
an abundant number because 1 + 2 + 3 + 4 + 6 = 16, and 16 > 12.
A number is a deficient number if it is greater than the sum of its proper divisors. For example, 9 is a
deficient number because 1 + 3 = 4, and 4 < 9.
A number is a perfect number if it is equal to the sum of its proper divisors. For example, 28 is a
perfect number because 1 + 2 + 4 + 7 + 14 = 28, and 28 = 28.
An algorithm should be written that creates three one-dimensional arrays, named ABUNDANT,
DEFICIENT and PERFECT , so that
the array ABUNDANT holds all the abundant numbers of the two-dimensional array MAT
the array DEFICIENT holds all the deficient numbers of the two-dimensional array MAT
the array PERFECT holds all the perfect numbers of the two-dimensional array MAT.
For example, if the 4 × 6 two-dimensional array MAT holds 24 positive integers, as follows:
then the three arrays should be:
[10]
Construct an algorithm in pseudocode to create the three one-dimensional arrays, ABUNDANT,
DEFICIENT and PERFECT , as described.
You may assume that the two-dimensional array MAT is inputted and three one‑dimensional arrays
of sufficient size are initialized.
The application:
sorts the input data in order of scores from the highest to the lowest by using a bubble sort algorithm.
outputs the sorted data.
(a.i) Describe the steps in the bubble sort algorithm that sorts the input data stored in the SCORES and
NAMES arrays in order of scores. [5]
A decision has been made to create a new application. It will use a binary tree as an alternative to the two arrays.
(c) The input data will be inserted into the binary tree so that an inorder traversal of the binary tree
would output all the students’ names and scores, sorted from the highest to the lowest score.
Algorithm 1 represents a method of searching the array DATA_ARR[] to see if it contains a specific value.
Algorithm 1
input TO_FIND
LIMIT = 11
LOC = FALSE
ITERATE = 0
loop while not LOC and ITERATE <= LIMIT
if DATA_ARR[ITERATE] = TO_FIND then
LOC = TRUE
end if
ITERATE = ITERATE + 1
end loop
if LOC then
output TO_FIND, "is in the array"
else
output TO_FIND, "is NOT in the array"
end if
(a) Copy and complete the trace table for Algorithm 1 using TO_FIND = 39.
The first value of the first row has been done for you.
[4]
Algorithm 2 represents an alternative method of searching the array DATA_ARR[] to see if it contains a specific
value.
Algorithm 2
input TO_FIND
LOC = FALSE
LOW_LIM = 0
UP_LIM = 11
loop while LOW_LIM <= UP_LIM and LOC = FALSE
MID_VAL = (LOW_LIM + UP_LIM) div 2
if DATA_ARR[MID_VAL] = TO_FIND then
LOC = TRUE
else
if TO_FIND < DATA_ARR[MID_VAL] then
UP_LIM = MID_VAL - 1
else
LOW_LIM = MID_VAL + 1
end if
end if
end loop
if LOC = TRUE then
output TO_FIND, "is in the array"
else
output TO_FIND, "is NOT in the array"
end if
(c) Copy and complete the trace table for Algorithm 2 using TO_FIND = 50.
The first two values of the first row have been done for you.
[4]
(e) Evaluate the use of a sequential search and a binary search including the advantages and
disadvantages of each. [5]
The grade boundaries for the individual grades are shown below:
(b) Construct an algorithm using pseudocode to take the marks that have been stored in MARK[],
convert them into the appropriate grade and store the calculated grades in GRADE[]. [5]
(c) Outline how the name, mark and grade in the three arrays correspond to the same student. [2]
(d) Construct an algorithm using pseudocode to output the names and grades of all students who
achieve a grade of Merit or Distinction. [3]
(e) Explain how you would change your algorithm in part (d) to allow a user to choose a grade and
output the names and marks of the students who have achieved this grade. [3]
Length of side = 10 cm
Apothem = 8.66 cm
= 6 × 10
= 60 cm
Area =
Perimeter × Apothem
= 60 × 8.66
= 259.8 cm2
From the flowchart, pseudocode is to be created that will include sub‑programs to calculate and return the perimeter
and area of the shape.
(a.i) Construct pseudocode for the body of the following sub-program to calculate and return the
perimeter of the shape.
SUB_PERIMETER(NUM_SIDES, LENGTH_SIDE)
// Pseudocode to be added [2]
end SUB_PERIMETER
(a.ii) Construct a similar sub-program to the one in part (i) to calculate and return the area of the shape.
You must use an appropriate name for the sub-program and appropriate names for the parameters. [4]
(a.iii) Construct pseudocode based on the flowchart to collect input from the user, call the sub-programs
created in parts (i) and (ii), and output the results. [5]
(b) Without using pseudocode, explain how your algorithms could be altered to also find the area and
circumference of a circle.
Note:
An expression written in this form is known as postfix notation, whereas an expression written the traditional way is
known as infix notation.
For example:
Infix notation: (8 − 5) * 7
Postfix notation: 8 5 − 7 *
Both the infix and postfix expressions have the same result: 21
A collection named RPN already stores an expression formatted in Reverse Polish notation.
The algorithm reads the values from the collection and, using a stack data structure, evaluates it.
RPN.resetNext()
loop while RPN.hasNext()
VALUE = RPN.getNext()
loop while not (VALUE = "+" or VALUE = "-" or VALUE = "*" or VALUE = "/")
stack.push(VALUE)
VALUE = RPN.getNext()
end loop
OPERAND2 = stack.pop()
OPERAND1 = stack.pop()
if VALUE = "+" then
NEW_VAL = OPERAND1 + OPERAND2
stack.push(NEW_VAL)
end if
if VALUE = "-" then
NEW_VAL = OPERAND1 - OPERAND2
stack.push(NEW_VAL)
end if
if VALUE = "*" then
NEW_VAL = OPERAND1 * OPERAND2
stack.push(NEW_VAL)
end if
if VALUE = "/" then
NEW_VAL = OPERAND1 / OPERAND2
stack.push(NEW_VAL)
end if
end loop
RESULT = stack.pop()
output "The result is: ", RESULT
(a) Copy and complete the trace table for the algorithm using the RPN collection data:
5 2 + 25 16 − * 3 /
[6]
(b) Explain why a stack is used in the process of evaluating the expression in the algorithm. [3]
An alternative data structure in which the expression used in part (a) may be stored is a binary tree. If the tree is
traversed using postorder tree traversal, the output is formatted in RPN.
(c) Outline the steps involved in traversing the given tree using postorder tree traversal. [4]
(d) State the output from the given tree using inorder tree traversal. [2]
(b) Outline one difference between a bubble sort algorithm and a selection sort algorithm. [2]
(b) Evaluate the use of designing and developing different parts of software products concurrently.
[3]
(c) Outline one way in which users can be informed of software updates.
[2]
(b) Evaluate the use of designing and developing different parts of software products concurrently.
[3]
(c) Outline one way in which users can be informed of software updates.
[2]
48. [Maximum mark: 2]
Distinguish between a variable and a constant. [2]
[4]
(c) Construct the algorithm from the flowchart using pseudocode. Add additional pseudocode to
ensure that input is validated to only allow positive integers to be entered. [6]
(d) Efficiency is an important consideration when designing algorithms to ensure they don’t waste
computer resources such as memory or processing time.
Suggest two design considerations that could be made to an algorithm that would make it more
efficient. [4]
(a) Construct a pseudocode algorithm that will store the surnames in one array and first names in
another. [4]
The names in the collection are kept in a random order. However, it would be more useful if they were kept in
alphabetical order.
(b) Construct a pseudocode algorithm that will sort the surnames into alphabetical order using the
bubble sort method. The order of the first names must also be changed so that they keep the same
index as their corresponding surname. [5]
The company’s staff list is now organized in the arrays in alphabetical order.
(c) Describe the process a binary search would follow to find a record in the surname array. [4]
(d) Outline one benefit of using sub-programmes to implement your algorithms from parts (a) and (b). [2]
The flowchart contains a logic error that will affect the algorithm’s functionality.
(a.i) Identify the logic error in the algorithm. [1]
(a.ii) Outline how the error in the algorithm identified in part (i) can be corrected. [2]
The algorithm is to be altered to restrict the values that are input to whole numbers between 0 and 1000.
(b) State the name of the method that could be used to restrict the values that are input. [1]
(c) A further change has been requested for the algorithm to enable it to calculate the average of all
the numbers entered. The average will be output when the algorithm terminates.
Based on the flowchart, construct this algorithm using pseudocode. You must include the required
changes:
A binary search algorithm is not used to find a particular name in array SNAMES.
(a) State the reason for not using a binary search. [1]
The school offers its sporting program to students and has a basketball team, a tennis team and a football team. Each
student must choose at least one of these three sports.
Three collections, BASKETBALL, TENNIS and FOOTBALL, are created. When a student chooses a sporting activity,
their ID number is added to the appropriate collection.
For example:
For example:
The football and tennis training sessions are held at the same time. The football coach would like to know how many
students will not be able to attend the football training session because they will be attending the tennis training
session.
(c) Construct an algorithm in pseudocode that will output the number of students who have chosen
both tennis and football. The method isIn() should be used in your answer. [3]
(d) The school coordinator would like to check whether there are students who have not yet chosen
any one of the three sports.
Construct an algorithm in pseudocode that will output the names of students who have not yet
chosen any one of the three sports. An appropriate message should be displayed if every student
has chosen a sport. [7]
Users have been troubled by slow speeds when accessing the internet.
(b) Outline two reasons why there might be a reduction in data transmission speed at certain times. [4]
(c) Outline two measures that the school could take to safeguard its data from unlawful access via the
internet. [4]
(d) The inventory of office supplies used in the school is stored on the computer as a single file.
Each of the office supplies in the inventory (such as paper, ink, toner, printers, pens, staplers, pencils
and scissors) has a unique ID number, name, maximum quantity, minimum quantity and remaining
quantity.
Outline the steps in an algorithm that would output a list of supplies with the quantity to be
ordered. [4]
Each element of MAT holds a number for a colour; 1 represents the colour black and 0 represents the colour white.
In an application, the black-and-white image can be inverted (all white pixels are changed to black, and all black
pixels are changed to white).
Method invert(N,A) accepts a positive integer N and an N × N two-dimensional array A that holds the data for a
simple black-and-white image; it returns the inverted N × N two-dimensional array A.
(a) Construct an algorithm in pseudocode for the method invert(N,A). [3]
This would mean the first row of the original MAT is the last column in the rotated MAT, the second row is the second-
to-last last column, … and the last row is the first column.
Consider the following algorithm fragment:
K=input()
loop for M=0 to K mod 4 - 1
A=rotate(N,A)
end loop
where:
N is an integer and A is the N × N two-dimensional array that holds data about an image
K(K>=0) is an integer showing how many times the image should be rotated
method rotate(N,A) accepts an integer N and an N × N two-dimensional array A representing an image. It
returns an N × N two-dimensional array representing the image rotated clockwise by 90°.
(b.i) State the number of degrees by which the image will be rotated if the input value of K is 3. [1]
(b.ii) Outline why it is more efficient that the loop in the given algorithm fragment executes (K mod
4) times instead of K times. You may give an appropriate example in your answer. [2]
The algorithm for method rotate(N,A) uses an additional N × N two-dimensional array, named The N ×
N dimensional array B is initialized and updated using the values from A to represent the image rotated clockwise by
90°.
(c) Construct the algorithm in pseudocode for the method rotate(N,A) described above. [3]
(d) To avoid inefficient use of memory, a new algorithm for the method rotate(N,A) is constructed.
The N × N two-dimensional array A should be rotated clockwise by 90°, without the use of any
additional arrays.
One way of rotating the two-dimensional array A clockwise by 90° is to transpose A, and then
reverse each row of A.
The transpose of A is formed by turning all the rows of A into columns. For example, the value in the
first row and third column (A[1][3]) is swapped with the value in the third row and first column (A[3]
[1]).
Construct the new algorithm in pseudocode for the method rotate(N,A) described above. [6]
K=1
N=1
M=2
loop while K < 5
output(N,M)
K=K+1
N=N+2
M=M*2
end loop [5]
N = 372
X = N DIV 100
Y = X + 10 * (N MOD 100 DIV 10)
Z = Y + (N MOD 10) * 100
Determine the values of variables X, Y, and Z after execution of this algorithm. Show your working.
[3]
A three-digit number has three digits: a hundreds digit, a tens digit and a units digit.
For example, for 406, its hundreds digit is 4, its tens digit is 0 and its units digit is 6.
An algorithm is needed to copy each three-digit number from the collection NUMBERS, where the hundreds digit is
smaller than its tens digit and its tens digit is smaller than its units digit, into a one-dimensinal array named THREE. If
there are no such numbers in the collection then an appropriate message should be displayed.
For example:
then the array THREE is empty and a message such as “No such numbers”, should be outputted.
(b) Construct this algorithm. You may assume that the array THREE is initialized with a sufficient
number of elements. [8]
(c) Describe how a selection sort algorithm could be used to sort the array THREE in ascending order.
[4]
N = 372
X = N DIV 100
Y = X + 10 * (N MOD 100 DIV 10)
Z = Y + (N MOD 10) * 100
Determine the values of variables X, Y, and Z after execution of this algorithm. Show your working.
[3]
A three-digit number has three digits: a hundreds digit, a tens digit and a units digit.
For example, for 406, its hundreds digit is 4, its tens digit is 0 and its units digit is 6.
An algorithm is needed to copy each three-digit number from the collection NUMBERS, where the hundreds digit is
smaller than its tens digit and its tens digit is smaller than its units digit, into a one-dimensinal array named THREE. If
there are no such numbers in the collection then an appropriate message should be displayed.
For example:
then the array THREE is empty and a message such as “No such numbers”, should be outputted.
(b) Construct this algorithm. You may assume that the array THREE is initialized with a sufficient
number of elements. [8]
(c) Describe how a selection sort algorithm could be used to sort the array THREE in ascending order.
[4]
LIMIT = 4
end loop
(a) Identify two variables that have been used in the algorithm. [1]
(b) Copy and complete the table below to trace the algorithm using the data set:
(c.ii) State the type of sort in the algorithm constructed in c(i). [1]
(d) Construct an algorithm fragment to output the data in the array VALUES[]. [2]
(e) The sorting algorithm could be part of a sub-program within a larger program.
Explain the benefits of using sub-programs when constructing a larger program. [3]
LIMIT = 4
end loop
(a) Copy and complete the table below to trace the algorithm using the data set:
20, 6, 38, 50, 40
[5]
(b.i) With reference to the algorithm in the flow chart, construct this algorithm in pseudocode so that it
performs the same function. [3]
(b.ii) State the type of sort in the algorithm constructed in b(i). [1]
(c) Construct an algorithm fragment to output the data in the array VALUES[] [2]
The data structure used in this algorithm is a one-dimensional array. The teacher decides to experiment with
alternative data structures.
(d) Explain the difference between a dynamic data structure and a static data structure. [3]
(e) Identify one alternative data structure for storing class marks. [1]
A=3
B=7
loop while B >= A
A=A+1
output(B − A)
B=B−1
end loop [4]
calcBMI(H, W)
X=H*H
B=W/X
return B
endcalcBMI
Boris weighs 104 kg and is 2.00 m tall. His BMI can be calculated by calling method calcBMI() as follows
The data about a group of adults and their height measurement (in metres) and weight measurement (in kg) is held
in three one-dimensional arrays.
Where
NAME is a one-dimensional array holding names (currently sorted in alphabetical order).
WEIGHT is a one-dimensional array holding weight measurement in kilograms.
HEIGHT is a one-dimensional array holding height measurement in metres.
For example,
NAME[0] is Annie.
Her weight measurement is 52.40 kg and can be found in WEIGHT[0].
HEIGHT[0] is 1.56 which represents Annie’s height measurement in metres.
(c) State the name of the person whose height is held in HEIGHT[3]. [1]
(d.i) Identify one reason why a binary search algorithm cannot be used to find the name of person
whose height is given. [1]
(d.ii) Describe how the name of person whose height is given could be output. [2]
(e) Construct an algorithm which will output the names of all the people whose BMI is greater than this
group’s average BMI.
(b) Explain two benefits of using sub-procedures within a computer program. [4]
(c) Identify three characteristics of a collection. [3]
Construct in pseudocode an algorithm, using the access methods of a collection, which will iterate
through the collection NUMBERS and count how many elements stored in the collection are in the
interval [−1,1].
swap(A,B)
TEMP = A
B = TEMP
A=B
end swap
(a.ii) Suggest how the algorithm used in method swap() would need to be modified to successfully
exchange the values of variables A and B. [2]
Method swapRows(MAT,K,L) swaps the elements of two rows (row K and row L) in the two‑dimensional array MAT.
For example,
(b) Use pseudocode to construct an algorithm for the method swapRows(). [4]
A game consists of four rounds. In each round a player can score up to 100 points.
The data about the game is sorted in alphabetical order of names and stored in the memory as follows
Where
PLAYERS is a one-dimensional array holding names of players (currently sorted in alphabetical order).
ROUNDS is a two-dimensional array holding players’ scores.
TOTALS is a one-dimensional array holding total scores.
For example,
PLAYER[1] is Boris. The total number of points he scored is 180 and this can be found in TOTALS[1].
Boris scored 40 points in the first round which can be found in ROUNDS[1][0].
The value stored in ROUNDS[1][2] is 50 which means that Boris scored 50 points in the third round.
(c.i) State Paul’s total score. [1]
(c.ii) State where Hugh’s score in the fourth round can be found. [1]
(d) All the data stored in memory should be sorted in ascending order of total score using selection sort.
For example, after sorting, the data given opposite will be held in memory as follows
Construct an algorithm that will sort all the data in ascending order.
In your solution you should call methods swap() and swapRows() given in part (a) and part (b). [6]
(a.i) Identify one hardware security measure that will ensure that confidential data from the Head Office
cannot be accessed. [1]
(a.ii) Identify one software security measure that will ensure that confidential data from the Head Office
cannot be accessed. [1]
The company also uses the internet to enable communication with employees working on exploration and
production in many remote geographical areas.
The sub-sea oil and gas exploration and production unit of the company relies on thousands of kilometres of
pipeline which are monitored by a computer control system which can detect leaks.
(c) Explain the environmental benefit of using a computer control system to monitor the pipeline. [3]
The process of detecting leaks is carried out by sensors which are continuously monitoring changes in the flow and
pressure of the liquids in the pipes.
If any of sensor values are outside of the acceptable parameters stored on a disk in the office, the following error
routines are performed:
(d) Explain the relationship between sensors, output transducers and processor in this situation. [4]
(e) Construct a system flowchart to represent the process described above. [5]