Topic - 4 - Computational Thinking
Topic - 4 - Computational Thinking
5. For an identified application, explain why a binary search would be preferred to a linear search. [3]
1|Page
6. Construct a trace table for the following algorithm. (N18)
2|Page
Section B
7. AA 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.(N20)
A binary search algorithm is not used to find a particular name in array SNAMES.
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:
The method isIn(X, COL) returns True if the ID number X is in the collection COL; False otherwise.
For example:
3|Page
• 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]
The school coordinator would like to check whether there are students who have not yet chosen any
one of the three sports.
d. 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]
8. The following flowchart represents a standard algorithm: (M21)
4|Page
c. Suggest two design considerations that could be made to an algorithm that would make it more
efficient. [4]
9. 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[]. (M 22)
The grade boundaries for the individual grades are shown below:
Algorithm 1 represents a method of searching the array DATA_ARR[] to see if it contains a specific
value.
Algorithm 1
5|Page
Copy and complete the trace table for Algorithm 1 using TO_FIND = 39.
a. 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
6|Page
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]
7|Page
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-dimensional 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:
A transport authority is investigating how many people use a certain direct train route, which is
used every day of the week.
8|Page
At the end of each day, the total number of passengers who travelled on this route is stored in a
collection, PASSENGERS.
The first item was written to the collection on Monday 1st January 2018.
b. Assuming that the first item read from the collection is from Monday 1st January 2018,
construct pseudocode that will read PASSENGERS into an array, P_ARRAY. [4]
c. Using P_ARRAY, construct pseudocode to output the day of the week with the highest average
number of passengers. Use the sub procedure convert () which converts the numbers 0 to 6 into
days of the week, for example convert(1) will return “Tuesday”. Note: you should not assume that
data for an exact number of weeks is stored. [7]
13. (a) Outline the need for higher level languages. [2](N18)
b. Explain two benefits of using sub-procedures within a computer program. [4]
c. Identify three characteristics of a collection. [3]
Collection NUMBERS already exists and stores real numbers.
d. 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]
14. 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).(N18)
9|Page
b. Use pseudocode to construct an algorithm which accepts a person’s BMI and outputs the weight
category the person belongs to. [4]
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]
(ii) Describe how the name of person whose height is given could be output. [2]
10 | P a g e
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]
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.(M19)
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
11 | P a g e
c. (i) With reference to the algorithm in the flow chart, construct this algorithm in pseudocode so
that it performs the same function. [3]
12 | P a g e
(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]
The sorting algorithm could be part of a sub-program within a larger program.
e. Explain the benefits of using sub-programs when constructing a larger program. [3]
13 | P a g e