0% found this document useful (0 votes)
31 views13 pages

Topic - 4 - Computational Thinking

Uploaded by

nadeemubaid21
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)
31 views13 pages

Topic - 4 - Computational Thinking

Uploaded by

nadeemubaid21
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/ 13

Section A

1. Distinguish between a variable and a constant. [2] (M21)


2. List the output from the given algorithm for the following input. [3](M21)

3. Construct a trace table for the following algorithm(N19)

4. Consider the following algorithm. (M18)

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)

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 y


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

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)

a. State the purpose of the algorithm. [1]


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

Efficiency is an important consideration when designing algorithms to ensure they don’t


waste computer resources such as memory or processing time.

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:

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]
10. The array DATA_ARR[] is a one-dimensional array of 12 integers.(M22)

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]

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

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]

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]
11. Consider the following algorithm. (N19)
N = 372
X = N DIV 100
Y = X + 10 * (N MOD 100 DIV 10)
Z = Y + (N MOD 10) * 100
a. 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 hundred digit, a tens digit and a unit’s digit. For
example, for 406, its hundreds digit is 4, its tens digit is 0 and its units’ digit is 6.

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:

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]
12. (a) The collection DATA contains the following data: (M18)
2, 4, 1, −2, −4, 1, 0
Consider the following pseudocode:

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)

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

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

You might also like