All papers

Computer Science · OCR H446 · Algorithms and programming · June 2019

OCR A Level Computer Science Algorithms and programming June 2019 question paper H446/02

2h 30m 140 marks

Practise the past exam questions by topic

OCR H446 · Paper 2

7 questions
Report a problem
What is wrong?

Goes to whoever maintains the question split. No account needed and nothing is published on this page.

Question 1

The temperatures of an ocean are input into a computer system. They are recorded, and will be accessed, in the order in which they arrive. The data for one week is shown:

5, 5.5, 5, 6, 7, 6.5, 6

(a)

The data is to be stored in a data structure. The programmer stores the data in a queue.

Explain why a queue is used instead of a stack.

[2]

(b)

The data is processed. After processing, the value for the first day is stored as 0. The value for each following day is stored as an increase, or decrease, from the first day.

For example: if the first day was 7, the second was 6 and the third was 9, after processing it would be stored as 0, –1, 2.

(b)(i)

The queue uses dequeue() to return the first element of the queue.

dequeue() is a function.

Explain why dequeue() is a function, not a procedure.

[1]

(b)(iii)

The contents of processedData are shown.

Figure for question 1

The data needs to be sorted into ascending order.

Explain how a bubble sort algorithm sorts data. Use the current contents of processedData in your explanation.

[5]

Question 2

A program needs to store the names of plants that are in a garden, so they can be easily found and accessed in alphabetical order.

The data is stored in a tree structure. Part of the tree is shown.

Figure for question 2
(a)
(a)(i)

State the type of tree shown in Fig. 2.1.

[1]

(a)(ii)

Show the output of a breadth-first traversal of the tree shown in Fig. 2.1.

[3]

(a)(iii)

Explain how backtracking is used in a depth-first (post-order) traversal. Use the tree in Fig. 2.1 in your explanation.

Figure for question 2

[4]

(b)

The elements in the tree in Fig. 2.1 are read into a linked list producing an alphabetised list.

(b)(i)

Complete the following table to show the linked list for the data.

Figure for question 2

[2]

(b)(ii)

A new plant, Lavender, needs adding to the linked list. The linked list needs to retain its alphabetical order.

Complete the table to show the linked list after Lavender is added.

Figure for question 2

[3]

(b)(iii)

Hosta needs removing from the linked list.

Explain how a data item is removed from a linked list. Use the removal of Hosta in your answer.

[4]

(b)(iv)

The linked list is stored as a 2D array with the identifier plantList. The index of the first element of the linked list is stored in the identifier firstElement.

All contents of the linked list need to be output in alphabetical order.

Write an algorithm to follow the pointers to output the contents of the linked list in alphabetical order.

Add comments to explain your code.

[5]

Question 3

A recursive function, GCD, is given in pseudocode.

Figure for question 3
(a)

The function uses branching.

(a)(i)

Identify the type of branching statement used in the function.

[1]

(a)(ii)

Explain the difference between branching and iteration.

[2]

(a)(iii)

Identify the two parameters in the function.

1

2.

[1]

(a)(iv)

State whether the parameters should be passed by value, or by reference. Justify your answer.

[2]

(a)(v)

Describe the arithmetic operation of MOD. Use an example in your answer.

[2]

(b)

Trace the recursive function when it is called by the statement GCD(250, 20). Give the final value returned.

Final return value:.

[3]

(c)

The function has been rewritten using iteration instead of recursion.

(c)(i)

State one benefit and one drawback of using iteration instead of recursion.

Benefit.

Drawback.

[2]

(c)(ii)

Complete the missing statements in this iterative version of the function.

Figure for question 3

[4]

Question 4

Mabel is a software engineer. She is writing a computer game for a client. In the game the main character has to avoid their enemies. This becomes more difficult as the levels of the game increase.

(a)

Mabel uses decomposition to design the program.

Explain how decomposition can aid the design of this program.

[2]

(b)

The computer game allows a user to select a character (e.g. name, gender). They can then choose a level for the game (easy, normal, challenging). The user controls their character by moving it left or right. The character can jump using space bar as an input. If the character touches one of the enemies then it loses a life. The character has to make it to the end of the level without losing all their lives.

The game is designed in a modular way.

(b)(i)

One sub-procedure will handle the user input.

Describe three other sub-procedures Mabel could create for the given game description.

[6]

(b)(ii)

Describe the decision that the program will need to make within the user input sub- procedure and the result of this decision.

[2]

(b)(iii)

Define pipelining and give an example of how it could be applied in the program.

[2]

(d)

*Mabel has been told that true programmers write programs in a text editor, and do not use IDEs. Mabel does not agree with this statement.

Discuss the use of an IDE in the development of this program.

[9]

Question 5

A 1-dimensional array stores the following data:

Index012345
Data21864123
(a)

The array needs sorting into descending order.

Describe how a merge sort would sort the given array into descending order.

[6]

(b)

An insertion sort can be used to sort the array instead of a merge sort.

Explain why an insertion sort might use less memory than a merge sort.

[2]

Question 6

6* Benedict runs a social networking website. He has been told he should use data mining to help him enhance and improve his website.

Evaluate the use of data mining to help Benedict enhance and improve his social networking website.

[9]

Question 7

Figure for question 7
(a)

The programmer will use abstraction to produce the program interface to represent the garden.

(a)(i)

Give two different examples of how abstraction has been used to produce the layout of the garden.

[2]

(a)(ii)

Explain the need for abstraction in the production of this program.

[3]

(a)(iii)

The user needs to input data into the program to set up their garden layout.

Identify three pieces of data that the user may input into this program.

[3]

(b)

The program is to be built using object oriented programming.

All items that can be added to the garden are declared as instances of the class GardenItem

The class has the following attributes:

Figure for question 7
(b)(i)

The constructor method sets the attributes to values that are passed as parameters.

Write pseudocode or program code to declare the class GardenItem and its constructor. All attributes should be private and initialised through the constructor (e.g. daisies =

new GardenItem("Flowerbed",2,1) maths symbol

[4]

(b)(ii)

The trees in the garden layouts are defined by the class Tree. This class inherits from GardenItem.

The class Tree has the additional attributes: height, sun, shade.

If sun is true then the tree can grow in full sun, if it is false then it cannot.

If shade is true then the tree can grow in full shade, if it is false then it cannot.

The length and width of a tree are the same. Only one value for these measurements is passed to the constructor.

Write an algorithm, using pseudocode or program code, to declare the class Tree Declare all attributes as private.

[5]

(b)(iii)

The Common Oak is a type of tree. It has a maximum height, length and width of 40 m. It can grow in sun and shade.

Write a statement, using pseudocode or program code, to declare an instance of tree for the Common Oak. Give the object the identifier firstTree.

[4]

(b)(iv)

The classes GardenItem and Tree use get and set methods to access and alter their private attributes.

Write the get method getItemName and set method setItemName for class GardenItem. The set method takes the new value as a parameter.

Do not write any other methods, or re-declare the class.

[4]

(c)

* The programmer is designing the program to make use of caching and re-useable components.

Explain and evaluate the use of caching and re-useable components in the design of the garden program.

[9]

The paper as printed

Spotted a mistake on this page?Report a problem