h446-02-june-2017-qp-ocr-a-level-computer-science
h446-02-june-2017-qp-ocr-a-level-computer-science
Do not use:
• A calculator
* H 4 4 6 0 2 *
First name
Last name
Centre Candidate
number number
INSTRUCTIONS
• Use black ink.
• Complete the boxes above with your name, centre number and candidate number.
• Answer all the questions.
• Write your answer to each question in the space provided. Additional paper may be
used if required but you must clearly show your candidate number, centre number and
question number(s).
• Do not write in the barcodes.
INFORMATION
• The total mark for this paper is 140.
• The marks for each question are shown in brackets [ ].
• Quality of extended responses will be assessed in questions marked with an
asterisk (*).
• This document consists of 28 pages.
Section A
dataArray[position] = …………………………
next x
endprocedure
[3]
© OCR 2017
3
(ii) Show how an insertion sort would sort the following data:
6 1 15 12 5 6 9
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [6]
(b) (i) Using Big-O notation state the best case complexity of insertion sort.
...................................................................................................................................... [1]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [3]
Insertion sort has a worst case time complexity of O(n2) and space complexity of O(1).
An alternative sorting algorithm that could be used is bubble sort which also has a worst case
time complexity of O(n2) and space complexity of O(1).
Briefly outline how the bubble sort algorithm works. Discuss the relationship between the
complexities and the two sorting algorithms and justify which of the two algorithms is best
suited to sorting the array. [9]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© OCR 2017
5
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© OCR 2017
7
2 A programmer is developing an ordering system for a fast food restaurant. When a member of
staff inputs an order, it is added to a linked list for completion by the chefs.
(a) Explain why a linked list is being used for the ordering system.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
Fig. 2.1 shows the current contents of the linked list, orders.
Fig. 2.1
(i) Order 158 has been made, and needs adding to the end of the linked list.
Add the order, 158, to the linked list as shown in Fig. 2.1. Show the contents of the linked
list in the following table.
[2]
[3]
Fig. 2.2
procedure x()
finished = false
count = 0
while NOT(finished)
if theOrders[1,count] == null then
finished = true
else
output = theOrders[0,count]
print(output)
count = theOrders[1,count]
endif
endwhile
output = theOrders[0,count]
print(output)
endprocedure
© OCR 2017
9
(i) Outline why nodeNo does not need to be stored in the array.
...........................................................................................................................................
...................................................................................................................................... [1]
(ii) Complete the trace table for procedure x, for the data shown in Fig. 2.2.
[3]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
Describe how the new order, 190, can be added to the array, so the linked list is read in
the correct order, without rearranging the array elements.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [4]
(d) The user needs to be able to search for, and find, a specific order number.
State an appropriate search algorithm that could be used, and justify your choice against an
alternative Search algorithm.
Justification ................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[3]
© OCR 2017
11
(e) The programmer is writing the program using an IDE.
Identify three features of an IDE that the programmer would use when writing the code and
describe how the features benefit the programmer.
1 .................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
2 .................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
3 .................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[6]
Discuss how concurrent programming can be applied to the food ordering system and the
benefits and limitations of doing so. [9]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© OCR 2017
13
3 An encryption routine reads a line of text from a file, reverses the order of the characters in the
string and subtracts 10 from the ASCII value of each letter, then saves the new string into the
same file.
The program is split into sub-procedures. Three sub-procedures are described as follows:
(a) (i) Identify one further sub-procedure that could be used in the program.
...................................................................................................................................... [1]
1 .........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
2 .........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
[4]
function …………………………………………………………(fileName)
messageFile = openRead(…………………………………………………………)
message = messageFile.readLine()
messageFile. …………………………………………………………
return …………………………………………………………
endfunction
[4]
theStack.push("H")
A procedure, pushToStack, takes a string as a parameter and pushes each character of the
message onto the stack, messageStack.
procedure pushToStack(message)
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
endprocedure
[5]
(d) Describe the steps that the program would have to take in order to encrypt the characters
stored in the stack, and save them in a single variable.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [5]
© OCR 2017
15
BLANK PAGE
A
B C
D X E F
H
G J
K I
N
L
M
Fig. 4.1
.............................................................................................................................................. [1]
(i) Explain the difference between a depth-first (post-order) and breadth-first traversal.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [4]
© OCR 2017
17
(ii) Show how a depth-first (post-order) traversal would find the path between node A and
node X for the structure shown in Fig. 4.1.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [6]
(iii) Explain how you used backtracking in your answer to part (b)(ii).
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [3]
.............................................................................................................................................. [1]
(b) Trace the algorithm, showing the steps and result when the following line is run:
print(calculate(4,10))
[5]
© OCR 2017
19
(c) Re-write the function so it uses iteration instead of recursion.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [4]
The user can choose the type of animal they would like as their pet, give it a name and then they are
responsible for caring for that animal. The user will need to feed, play with, and educate their pet.
The aim is to keep the animal alive and happy, for example if the animal is not fed over a set
period of time then the pet will die.
• The game tells the user how hungry or bored the animal is as a percentage (%) and
the animal’s intelligence is ranked as a number between 0 and 150 (inclusive).
• Hunger and boredom increase by 1% with every tick of a timer.
• When the feed option is selected, hunger is reduced to 0.
• When the play option is selected, bored is reduced to 0.
• When the read option is selected, the intelligence is increased by 0.6% of its current
value.
Fig. 1.1
(a) Identify three inputs that the user will have to enter to start, and/or play the game.
1 .................................................................................................................................................
2 .................................................................................................................................................
3 .................................................................................................................................................
[3]
© OCR 2017
21
(b) The developer is using decomposition to design the game.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
(ii) The developer has produced the following structure diagram for the game:
Virtual Pet
Reduce
Hunger to 0
Complete the structure diagram for the Virtual Pet game by filling in the empty boxes.
[6]
(i) Write a procedure, using pseudocode, to reset bored and output the new value in an
appropriate message.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [3]
(ii) Write a procedure, using pseudocode, to increase intelligence by 0.6% and output
the new intelligence in an appropriate message.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [3]
© OCR 2017
23
(d) The developer is extending the game to allow users to have multiple pets of different types.
The developer has written a class, Pet.
The attributes and methods in the class are described in the table:
class Pet
private petName
private bored
private hunger
private intelligence
private type
…
…
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [4]
(ii) Write a line of code that creates a new instance of Pet for a Tiger called “Springy”.
...................................................................................................................................... [2]
© OCR 2017
25
(iii) The method outputGreeting for the superclass is written as follows:
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [5]
Discuss the need for and purpose of abstraction and how abstraction will be used in the
development of the game. [9]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
© OCR 2017
27
(f) The developer is storing the user’s pets in a 1-dimensional array. At each timer interval, the
array is searched, using a linear search, to check if any pets’ hunger or bored values are
greater than 90%. If they are, an alert is displayed to the user.
...................................................................................................................................... [1]
(ii) A given computer takes 4 milliseconds (ms) to search an array of 20 pets. Calculate an
estimate of how long the computer will take to search an array of 100 pets.
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [2]
© OCR 2017
28
© OCR 2017