0% found this document useful (0 votes)
38 views52 pages

Topic 4 Math Test

The document outlines a series of test questions related to Boolean operators, logic diagrams, algorithms, and string manipulation in programming. It includes tasks such as defining the NOR operator, constructing logic diagrams for car motion scenarios, and writing pseudocode for various algorithms. Additionally, it covers topics like sorting algorithms, password validation, and concurrent processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views52 pages

Topic 4 Math Test

The document outlines a series of test questions related to Boolean operators, logic diagrams, algorithms, and string manipulation in programming. It includes tasks such as defining the NOR operator, constructing logic diagrams for car motion scenarios, and writing pseudocode for various algorithms. Additionally, it covers topics like sorting algorithms, password validation, and concurrent processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Topic 4 test [647 marks]

1. [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.

Figure 1: Rules to control car motion

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:

Output Z equals 1 when:

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.

In all other conditions, output Z equals 0. [4]

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).

Figure 2: Identifiers for car motion rules


(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

F >= 25 AND S >= 10 AND S <= 130 AND T = true

You must show your working. [2]

(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]

2. [Maximum mark: 15]


(a) Describe one standard operation of collections. [2]

The collection RAINBOW holds the names of the main colours of the rainbow along with their order indicator, as
follows:

Blue, E, Green, D, Indigo, F, Orange, B, Red, A, Violet, G, Yellow, C

(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]

3. [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.

Figure 1: Rules to control car motion

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:

Output Z equals 1 when:

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.

In all other conditions, output Z equals 0. [4]

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).

Figure 2: Identifiers for car motion rules

(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

F >= 25 AND S >= 5 AND S <= 130 AND T = true [2]

You must show your working.

(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]

4. [Maximum mark: 15]


(a) Describe one standard operation of collections. [2]

The collection CAPITALS holds the names of a number of capital cities and the names of their corresponding
countries, as follows:

Ankara, Turkey, Brasilia, Brazil, Dhaka, Bangladesh, Lisbon,


Portugal, Manila, Philippines, Rome, Italy

(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]

5. [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.

Figure 1: Rules to control car motion


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:

Output Z equals 1 when:

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.

In all other conditions, output Z equals 0. [4]

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).

Figure 2: Identifiers for car motion rules

(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

F >= 25 AND S >= 10 AND S <= 130 AND T = true


You must show your working. [2]

(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]

6. [Maximum mark: 15]


String manipulation is a useful programming concept.

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 set of string manipulation sub-programs is given in Figure 4.

Figure 4: String manipulation sub-programs

(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:

MARGORIE, 0, 6, SPOT, 1, 3, EZEKIEL, 2, 3, LISA, 0, 2

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]

7. [Maximum mark: 15]


String manipulation is a useful programming concept.

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 set of string manipulation sub-programs is given in Figure 4.

Figure 4: String manipulation sub-programs

(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:

ADONUS, 3, 2, FERGUS, 0, 3, NASREEN, 1, 4, TUPPENCE, 0, 3, DAMOCLES, 2, 3

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.

Figure 1: Rules to control car motion

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:

Output Z equals 1 when:

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.

In all other conditions, output Z equals 0. [4]

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).

Figure 2: Identifiers for car motion rules


(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

F >= 25 AND S >= 5 AND S <= 130 AND T = true

You must show your working. [2]

(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]

10. [Maximum mark: 2]


Outline what is meant by a virtual machine. [2]

11. [Maximum mark: 3]


(a) Outline what is meant by concurrent processing. [2]

(b) Identify one advantage of concurrent processing. [1]

12. [Maximum mark: 6]


(a) Construct a trace table for the following algorithm:

N = 1216
X=0
loop while N > 0
X = X + N mod 10
N = N div 10
end loop
output (X) [4]

(b) Deduce the purpose of the algorithm. [2]


13. [Maximum mark: 15]
There were 10 gymnasts who took part in a gymnastics competition. The names and the scores for all competitors
were sorted in alphabetical order and stored in two arrays, NAMES and SCORES (see Figure 1).

Figure 1: Data held in the NAMES array and the SCORES array

For example, the score awarded to Mary Allen was 6.5 .

(a) State the name of the gymnast whose score is stored in SCORES[5].
[1] 

(b) Construct an algorithm in pseudocode to determine the average score.


[3] 

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] 

An algorithm is needed that:

allows input of a gymnast’s name


searches for this name in the NAMES array using a binary search
outputs the gymnast’s score. If the inputted name does not occur in the NAMES array, it outputs an appropriate
message.

For example, from the data given in Figure 1:

if “Allen, Mary” is the input name, then 6.5 should be output


if “Peterson, Tina” is the input name, then a message saying “this name is not found” should be output.
(d) Construct an algorithm in pseudocode as described above.
[7] 

14. [Maximum mark: 15]


There were 10 gymnasts who took part in a gymnastics competition. The names and the scores for all competitors
were sorted in alphabetical order and stored in two arrays, NAMES and SCORES (see Figure 1).

Figure 1: Data held in the NAMES array and the SCORES array

For example, the score awarded to Mary Allen was 6.5 .

(a) State the name of the gymnast whose score is stored in SCORES[5].
[1] 

(b) Construct an algorithm in pseudocode to determine the average score.


[3] 

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] 

An algorithm is needed that:

allows input of a gymnast’s name


searches for this name in the NAMES array using a binary search
outputs the gymnast’s score. If the inputted name does not occur in the NAMES array, it outputs an appropriate
message.
For example, from the data given in Figure 1:

if “Allen, Mary” is the input name, then 6.5 should be output


if “Peterson, Tina” is the input name, then a message saying “this name is not found” should be output.
(d) Construct an algorithm in pseudocode as described above.
[7] 

15. [Maximum mark: 2]


Outline what is meant by a virtual machine. [2]

16. [Maximum mark: 3]


(a) Outline what is meant by concurrent processing. [2]

(b) Identify one advantage of concurrent processing. [1]

17. [Maximum mark: 2]


Outline what is meant by a collection. [2]

18. [Maximum mark: 6]


Given the integer array DATA:

and the following algorithm:

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]

(b) Deduce the purpose of this algorithm. [2]

19. [Maximum mark: 2]


Outline what is meant by the term “abstraction”. [2]

20. [Maximum mark: 15]


There are 1000 rooms where students can live on a college campus. The rooms are numbered from 1 to 1000. The bill
for each room must be paid each month.

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).

Figure 1: Example data stored in the ROOMNUMS array

For example, the bill for room number 93 has been paid. This can be seen in ROOMNUMS[6].

(a) State two characteristics of a linear array. [2]

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.

(b) Identify two types of searching algorithm. [2]

Figure 2 shows two examples of input and output for the data stored in the ROOMNUMS array as given in Figure 1.

Figure 2: Examples of input and output

(c) Construct an algorithm in pseudocode for the sub-program check(). [5]

(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]

22. [Maximum mark: 2]


Outline what is meant by the term “abstraction”. [2]

23. [Maximum mark: 15]


There are 1000 rooms where students can live on a college campus. The rooms are numbered from 1 to 1000. The bill
for each room must be paid each month.

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).

Figure 1: Example data stored in the ROOMNUMS array

For example, the bill for room number 93 has been paid. This can be seen in ROOMNUMS[6].

(a) State two characteristics of a linear array. [2]

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.

(b) Identify two types of searching algorithm. [2]

Figure 2 shows two examples of input and output for the data stored in the ROOMNUMS array as given in Figure 1.

Figure 2: Examples of input and output

(c) Construct an algorithm in pseudocode for the sub-program check(). [5]

(d) Construct an algorithm in pseudocode to sort the ROOMNUMS array in ascending order using the
selection sort algorithm.
[6]

24. [Maximum mark: 6]


Given the integer array DATA:

and the following algorithm:

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

(a) Construct a trace table for this algorithm. [4]

(b) Deduce the purpose of this algorithm. [2]

25. [Maximum mark: 2]


Outline what is meant by a collection. [2]

26. [Maximum mark: 15]


A program is developed to simulate the roll of dice in a game.

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 product 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,1) returns 4

DuplicateNum(DICEDIAL,2) returns 0

(b) Construct an algorithm in pseudocode for the sub-program DuplicateNum(DICEDIAL,R). [4]

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.

(c) Construct an algorithm in pseudocode for the sub-program lowestRT(DICEDIAL). [8]

27. [Maximum mark: 2]


Outline what is meant by a collection. [2]

28. [Maximum mark: 15]


A program is developed to simulate the roll of dice in a game.

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,1) returns 4

DuplicateNum(DICEDIAL,2) returns 0

(b) Construct an algorithm in pseudocode for the sub-program DuplicateNum(DICEDIAL,R). [4]

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.

(c) Construct an algorithm in pseudocode for the sub-program highestRT(DICEDIAL). [8]

29. [Maximum mark: 1]


Define the term variable. [1]

30. [Maximum mark: 4]


Given the one-dimensional array NAMES:
construct a trace table for the following algorithm:

K=3
loop while K>=0
A=K mod 3
[4]
output (NAMES[A])
K=K−1
end while

31. [Maximum mark: 15]


An integer divisor of an integer, N(N>0), is an integer greater than zero that divides N without leaving a remainder.
The proper divisors of N are divisors of N other than N itself.

For example:

The divisors of 10 are 1, 2, 5 and 10.


The proper divisors of 10 are 1, 2 and 5.

(a.i) State the number of proper divisors of 2.


[1] 

(a.ii) State why 4 is not a proper divisor of 10.


[1] 

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.
Construct an algorithm in pseudocode to:

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 should call the isAbundant() subprogram.


[7] 
You can assume that the value of X and the array DATA have already been inputted.

32. [Maximum mark: 5]


(a) Identify two fundamental operations of a computer.
[2] 

(b) Explain the need for higher level languages.


[3] 

33. [Maximum mark: 15]


An integer divisor of an integer, N(N>0), is an integer greater than zero that divides N without leaving a remainder.
The proper divisors of N are divisors of N other than N itself.

For example:

The divisors of 10 are 1, 2, 5 and 10.


The proper divisors of 10 are 1, 2 and 5.

(a.i) State the number of proper divisors of 2.


[1] 

(a.ii) State why 4 is not a proper divisor of 10.


[1] 

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.

Construct an algorithm in pseudocode to:

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 should call the isAbundant() subprogram.

You can assume that the value of X and the array DATA have already been inputted. [7] 

34. [Maximum mark: 5]


(a) Identify two fundamental operations of a computer.
[2] 

(b) Explain the need for higher level languages.


[3] 

35. [Maximum mark: 2]


Outline the need for a translation process from a higher level language to a lower level language. [2]

36. [Maximum mark: 4]


Given the one-dimensional array NAMES:

and the following recursive algorithm:

mystery(A, N) // A is a one-dimensional array, N is an integer


if N>0 then
mystery(A, N−1)
end if
output(A[3−N])
end mystery

determine the output produced after execution of the following statement:

mystery(NAMES, 3)
Show all your working. [4]

37. [Maximum mark: 15]


An integer divisor of an integer, N(N>0), is an integer greater than zero that divides N without leaving a remainder.
The proper divisors of N are divisors of N other than N itself.

For example:

The divisors of 10 are 1, 2, 5 and 10.


The proper divisors of 10 are 1, 2 and 5.

X(X>0) and Y(Y>0) are two integers.

(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).

(b) Construct an algorithm in pseudocode for the subprogram sumPD(N). [3]

(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.

Assume that the two-dimensional array MAT holds positive integers.

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.

You should call the sumPD() subprogram in your algorithm.

38. [Maximum mark: 15]


A list of students’ names and test scores are written in a teacher’s notebook in alphabetical order. The teacher uses an
application that allows her to input all of the names and scores in the order they appear in her notebook. The
application orders the scores from highest to lowest and then outputs all the names and scores (see Figure 1).

Figure 1: An example of the input and output of the application

The application:

inputs the names and scores


stores the input data in two arrays: NAMES and SCORES (see Figure 2)

Figure 2: The NAMES and SCORES arrays


For example, NAMES[3] holds the student’s name (Emma), and her score (87) can be found in SCORES[3].

The application also:

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.ii) Identify one alternative sorting algorithm. [1]

A decision has been made to create a new application. It will use a binary tree as an alternative to the two arrays.

(b) Identify the components of a node in a binary tree. [3]

(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.

Describe the steps in this insertion process. [6]

39. [Maximum mark: 2]


Outline the need for a translation process from high level language to machine code. [2]

40. [Maximum mark: 15]


The array DATA_ARR[] is a one-dimensional array of 12 integers.

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]

(b) State the constant used in Algorithm 1. [1]

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]

(d) Outline why MID_VAL could not be a constant. [1]

(e) Evaluate the use of a sequential search and a binary search including the advantages and
disadvantages of each. [5]

41. [Maximum mark: 15]


A teacher would like a simple program to store the names, marks and grades of students in a set of three parallel one-
dimensional arrays called NAME[], MARK[] and GRADE[] .

The grade boundaries for the individual grades are shown below:

The class has 30 students.

(a) Identify two components in a conditional statement. [2]

(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]

42. [Maximum mark: 15]


The flowchart below represents an algorithm that allows a user to enter the number of sides, length of side and
apothem (see diagram below) for a regular polygon. It then calculates and outputs the area and perimeter of this
shape.

Worked example: a regular hexagon


Number of sides = 6

Length of side = 10 cm

Apothem = 8.66 cm

Perimeter = Number of sides × Length of side

= 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:

Area of circle = πr2

Circumference of circle = 2πr [4]

43. [Maximum mark: 15]


Reverse Polish notation (RPN) is a method used to represent mathematical expressions so they can be evaluated
without the need for parentheses.

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

RPN expressions are evaluated from left to right as follows:

Each character is checked,


if it is a digit, it is pushed onto a stack.
if it is a mathematical operator, the last two digits are popped from the stack and evaluated as though the
current operator was between them. The result of this operation is then pushed back onto the stack.
The process is repeated until all the characters in the RPN expression have been used.
The value left in the stack is the result of the expression.

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]

44. [Maximum mark: 2]


Assume X = 5, Y = 3 and A = TRUE.

Determine the value of the following expression:

((X > 5) XOR A) AND (Y + 2 > 4)

Show all your working. [2]

45. [Maximum mark: 4]


(a) Outline what is meant by a sorting algorithm. [2]

(b) Outline one difference between a bubble sort algorithm and a selection sort algorithm. [2]

46. [Maximum mark: 7]


A group of programmers are involved in creating a new software product. They create many new sub-programs but
also use existing sub-programs within the product.

(a) Outline why a sub-program is considered an example of abstraction.


[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] 

47. [Maximum mark: 7]


A group of programmers are involved in creating a new software product. They create many new sub-programs but
also use existing sub-programs within the product.

(a) Outline why a sub-program is considered an example of abstraction.


[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]

49. [Maximum mark: 3]


List the output from the given algorithm for the following input.

2, 6, 8, 9, 12, 15, 18, 20

loop for Count from 0 to 7


input NUMBER
if NUMBER div 2 = NUMBER / 2 then
if NUMBER div 3 = NUMBER / 3 then
output NUMBER
end if
end if
end loop [3]

50. [Maximum mark: 15]


The following flowchart represents a standard algorithm:
(a) Copy and complete the table that traces the algorithm in the flowchart using an input value of 19.

[4]

(b) State the purpose of the algorithm. [1]

(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]

51. [Maximum mark: 15]


A company has 600 employees whose names are currently stored using a collection called NAMES. The names are
stored as surname, first name. For example: Smith, Jane, Uysal, Rafael, Ahmed, Ishmael, Jonsonn, Sara, …

(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.

A binary search was used to find a specific name in the array.

(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]

52. [Maximum mark: 12]


The following flowchart is intended to represent an algorithm in which numbers that are input cannot be negative.

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:

correction of logic error


only allow input of integers between 0 and 1000
calculation of average of all numbers entered
output of final average. [8]

53. [Maximum mark: 4]


Describe the steps involved in using the bubble sort algorithm to sort an array. [4]

54. [Maximum mark: 15]


A school has 100 students. All student names (strings) and student ID numbers (five-digit integers) are held in two
separate one-dimensional arrays named SID and SNAMES.

For example, student Pia Baranger has ID number 11876.

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:

BASKETBALL={10011, 11876, 10122}


TENNIS={10011, 11876, 10002}
FOOTBALL={10011, 10002, 22103, 32000}

The method isIn(X, COL) is available, where:

X is a five-digit integer representing an ID number


COL is a collection that holds student ID numbers.
The method isIn(X, COL) returns True if the ID number X is in the collection COL; False otherwise.

For example:

isIn(11876, BASKETBALL) returns True


isIn(11876, FOOTBALL) returns False
(b) Construct an algorithm in pseudocode for the method isIn(X, COL). [4]

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]

55. [Maximum mark: 15]


A school has a local area network (LAN) connecting its computers and peripheral devices. The LAN also provides
access to the internet.

(a) Describe the role of a router in this network. [3]

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]

56. [Maximum mark: 15]


Images in computers are stored as two-dimensional arrays.
A black-and-white image (Figure 1) is stored as a 10 × 10 two-dimensional array named MAT (Figure 2).

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]

In the application, it is also possible to rotate an image clockwise by 90 degrees (90°).


For example, when the simple black-and-white image is rotated, the corresponding 10 × 10 two-dimensional array
MAT is updated.

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]

57. [Maximum mark: 3]


Explain why abstraction is required in the design of algorithms. [3]

58. [Maximum mark: 5]


Construct a trace table for the following algorithm.

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]

59. [Maximum mark: 3]


(a) Identify one fundamental operation of a computer. [1]

(b) Distinguish between fundamental and compound operations of a computer. [2]

60. [Maximum mark: 15]


(a) Consider the following algorithm.

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] 

NUMBERS is a collection that holds only positive integers.

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:

If NUMBERS = {9, 3456, 12, 237, 45679, 368, 296}

then the contents of the array, THREE, is:

If NUMBERS = {1234, 56, 90, 324, 876}

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] 

61. [Maximum mark: 15]


(a) Consider the following algorithm.

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] 

NUMBERS is a collection that holds only positive integers.

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:

If NUMBERS = {9, 3456, 12, 237, 45679, 368, 296}

then the contents of the array, THREE, is:

If NUMBERS = {1234, 56, 90, 324, 876}

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] 

62. [Maximum mark: 2]


Compilers translate source code into object code. Identify two other operations performed by a compiler. [2]

63. [Maximum mark: 15]


A school teacher decides to write a program to store class records and marks. Part of this program involves using a
sort algorithm. The algorithm shown is a selection sort and to test it, the teacher has set up an array VALUES[] with 5
elements of test data.

LIMIT = 4

loop COUNTER1 from 0 to LIMIT – 1


MINIMUM = COUNTER1

loop COUNTER2 from COUNTER1 + 1 to LIMIT


if VALUES[COUNTER2] < VALUES[MINIMUM] then
MINIMUM = COUNTER2
end if
end loop

if MINIMUM ≠ COUNTER1 then


TEMPORARY = VALUES[MINIMUM]
VALUES[MINIMUM] = VALUES[COUNTER1]
VALUES[COUNTER1] = TEMPORARY
end if

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:

20, 6, 38, 50, 40


[5]
(c.i) With reference to the algorithm in the flow chart, construct this algorithm in pseudocode so that it
performs the same function. [3]

(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]

64. [Maximum mark: 15]


A school teacher decides to write a program to store class records and marks. Part of this program involves using a
sort algorithm. The algorithm shown is a selection sort and to test it, the teacher has set up an array VALUES[] with 5
elements of test data.

LIMIT = 4

loop COUNTER1 from 0 to LIMIT – 1


MINIMUM = COUNTER1

loop COUNTER2 from COUNTER1 + 1 to LIMIT


if VALUES[COUNTER2] < VALUES[MINIMUM] then
MINIMUM = COUNTER2
end if
end loop

if MINIMUM ≠ COUNTER1 then


TEMPORARY = VALUES[MINIMUM]
VALUES[MINIMUM] = VALUES[COUNTER1]
VALUES[COUNTER1] = TEMPORARY
end if

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]

65. [Maximum mark: 4]


Construct a trace table for the following algorithm

A=3
B=7
loop while B >= A
A=A+1
output(B − A)
B=B−1
end loop [4]

66. [Maximum mark: 15]


The following method, calcBMI() accepts person’s height (H) in metres (m) and weight (W) in kilograms (kg) and
returns their Body Mass Index (BMI).

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

BorisBMI = calcBMI(2.00, 104).

(a) State the value of variable BorisBMI. [1]

A person can belong to one of the following four weight categories:


(b) Use pseudocode to construct an algorithm which accepts a person’s BMI and outputs the weight
category the person belongs to. [4]

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.

You should call method calcBMI() in your answer. [6]

67. [Maximum mark: 15]


(a) Outline the need for higher level languages. [2]

(b) Explain two benefits of using sub-procedures within a computer program. [4]
(c) Identify three characteristics of a collection. [3]

(d) Collection NUMBERS already exists and stores real numbers.

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].

The final answer should be output. [6]

68. [Maximum mark: 15]


The following method, swap(A,B) is written to exchange the values of variables A and B.

swap(A,B)
TEMP = A
B = TEMP
A=B
end swap

(a.i) Assume A = 3 and B = 5.

State the values of A and B after execution of swap(A,B). [1]

(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]

69. [Maximum mark: 15]


An oil and gas company has a networked computer system for use of their employees in the Head Office.

(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.

(b) Identify one network security measure. [1]

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.

This data is processed on a computer in the office.

If any of sensor values are outside of the acceptable parameters stored on a disk in the office, the following error
routines are performed:

an alarm is sounded on the computer at the office


an email message is sent to managers in the Head Office.

(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]

© International Baccalaureate Organization, 2025

You might also like