Computational Thinking Algorithms and Programming
Computational Thinking Algorithms and Programming
First name(s)
Last name
INSTRUCTIONS
• Use black ink.
• Write your answer to each question in the space provided. If you need extra space use the lined
pages at the end of this booklet. The question numbers must be clearly shown.
• Answer all the questions.
INFORMATION
• The total mark for this paper is 80.
• The marks for each question are shown in brackets [ ].
• This document has 17 pages.
ADVICE
• Read each question carefully before you start to answer.
Section A
…………………………………………………………………………………………………………….
……………………………………………………………………………………………………………. [2]
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
[6]
© OCR 2019
3
2 (a) Complete the truth table in Fig. 1 for the Boolean statement P = NOT(A OR B) AND C.
A B C D E F
0 0
0 1
1 0
1 1
Fig. 1
[4]
(b) Draw a logic diagram for P = NOT(A AND B).
[4]
3 26 92 48 7 19 5
Fig. 3
(a) Show the stages of a merge sort when applied to data shown in Fig. 3.
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
[4]
(b) Explain why the data set above cannot be sorted with a binary sort.
………………………………………………………………………………………………………………
…………………………………………………………………………………………………………..…..
………………………………………………………………………………………………………………
…………………………………………………………………………………………………………..…..
[2]
© OCR 2019
5
7 46 17 54 3 31 2
(c) Show how a linear search would search for the number 54 in the list above.
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
(d) Create an algorithm that returns the value of an index requested in the array from user input.
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
[5]
4 The database table rank stores the rank for each student.
Complete the SQL query to return all the fields for students with a coding level above 5 with good conduct.
SELECT ……………………………………………………………….…………….…….…….…………
FROM ……………………………………………………………….…………….…….…….…………
WHERE ……………………………………………………………….…………….…….…….…………
[4]
© OCR 2019
7
5 The following program uses a works out whether a number is in the 2 times tables or not.
(a) Fill in the blanks.
x = ……………………………………………………………………
if x ………(2) == 0
[4]
Operator Purpose
DIV
[3]
……………………………………………………………..…………………………………………………..
[1]
……………………………………………………………..…………………………………………………..
[1]
(c) Complete the following trace table for the given algorithm where the first name “Simely”,
surname “Thomas” and year “2007” are entered.
02
03
04
05
[4]
© OCR 2019
9
Section B
Some questions require you to respond using either the OCR Exam Reference Language or a
high-level programming language you have studied. These are clearly shown.
String
Integer
Real
Boolean
Explanation: ……………………………………………………………………………………………….
…………………………………….………………………………………………….……………………..
[2]
(i) Complete the following program to output "Invalid input" if the data does not meet the
validation rule.
[3]
(ii) Complete the following test plan for the program in 8(b)(i).
Invalid input
Invalid
message displayed
Value accepted
18
[2]
© OCR 2019
11
(c)
Data for one week of pay (Monday to Friday) is stored in a 2D array with the identifier salary.
Students
The banker wants to output the daily pay for Fin (column index 3) on Tuesday (row index 1). The
following code is written:
print(salary[3,2])
Write a line of code to output the pay that Madison received on Thursday
…………………………………………………………………………………………………………
……………………………………………………………………………………………………… [1]
(d)
The banker wants to work out the amount Madison earnt last week
total = 0
print(total)
Refine the program to be more efficient. Write the refined version of the algorithm. You
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………………..
[4]
© OCR 2019
13
(e)
The following program uses a condition-controlled loop.
x x=="banana" output
[4]
(f)
A teacher writes an algorithm to store the name of the game a student plays each night (for example
"OCR weather-teller").
weather = input("Is it hot, cold or wet")
if weather =="hot":
print("wear a t-shirt")
elif weather =="cold":
print("wear a jacket")
elif weather =="wet":
print("wear a raincoat")
else:
print("Suck your mum")
The algorithm needs testing to make sure the IF-ELSE statement works correctly.
Identify two different pieces of test data that can be used to test different outputs of the
algorithm. Give the output from the program for each piece of test data.
© OCR 2019
15
(g)
The teacher asks students how long they spend revising. Students answer in minutes and hours (for
example 2 hours 15 minutes).
The teacher would like to create an algorithm that will display students’ inputs in minutes only.
(i) Identify the input and output required from this algorithm.
Input …….………………………………………………………………………………………………
……...……………………………………………………………………………………………………
Output …..………………………………………………………………………………………………
…….………………………………………………………………………….……………………........
[2]
(ii) A program is created to convert hours and minutes into a total number of minutes.
The teacher wants to create a sub program to perform the calculation. The
Total = ………………………………………………………………..
print(Total)
function ………………………………………………………………..
………………………………………………………………..
………………………………………………………………..
………………………………………………………………..
………………………………………………………………..
endfunction
[4]
(iii)
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
[6]
© OCR 2019
17
If additional space is required, you should use the following lined page(s). The question number(s) must
be clearly shown in the margin(s).
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
..................................................................................................................................................................
Copyright Information:
OCR is committed to seeking permission to reproduce all third-party content that it uses in the assessment materials. OCR has attempted to identify and
contact all copyright holders whose work is used in this paper. To avoid the issue of disclosure of answer-related information to candidates, all copyright
acknowledgements are reproduced in the OCR Copyright Acknowledgements booklet. This is produced for each series of examinations and is freely
available to download from our public website (www.ocr.org.uk) after the live examination series.
If OCR has unwittingly failed to correctly acknowledge or clear any third-party content in this assessment material, OCR will be happy to correct its
mistake at the earliest possible opportunity.
For queries or further information please contact the Copyright Team, The Triangle, Shaftesbury Road, Cambridge, CB2 8EA.
OCR is part of the Cambridge Assessment Group; Cambridge Assessment is the brand name of University of Cambridge Local Examinations Syndicate
(UCLES), which is itself a department of the University of Cambridge
© OCR 2019
18