All papers

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

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

2h 30m 140 marks

Practise the past exam questions by topic

OCR H446 · Paper 2

6 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

A program stores entered data in a binary search tree.

The current contents of the tree are shown:

Figure for question 1
(a)

Complete the diagram to show the contents of the tree after the following data is added:

England, Scotland, Wales, Australia

[3]

(b)

Show the order of the nodes visited in a breadth first traversal on the following tree.

Figure for question 1

[3]

(c)

A pseudocode algorithm is written to search the tree to determine if the data item “Sweden” is in the tree.

The function currentNode.left()returns the node positioned to the left of currentNode

Figure for question 1
(c)(ii)

The algorithm needs to be used in different scenarios, with a range of different trees.

Identify two preconditions needed of a tree for this algorithm to work.

[2]

Question 2

A company merger is joining five e-commerce retailers under one company, OCRRetail. Each retailer has a different sales system and OCRRetail wants to develop one computer system that can be used by all the retailers.

Mary’s software development company has been employed to analyse and design a solution for the company.

(a)
(a)(i)

Two computational methods (techniques used to solve a problem using computational thinking) that Mary will use are problem recognition and decomposition.

State what is meant by problem recognition and decomposition.

Question 2, shown as an image
Question 2, shown as an image

[2]

(a)(ii)

State one additional computational method.

Figure for question 2

[1]

(b)

Mary plans to use data mining to generate information about OCRRetail’s customers. Mary will use this information to benefit the company.

(b)(i)

Define the term ‘data mining’.

Figure for question 2

[1]

(b)(ii)

Identify two pieces of information that data mining could provide OCRRetail about sales, and state how OCRRetail could make use of this information.

Question 2, shown as an image

maths symbol

[4]

(c)

Mary has developed the program and is considering using performance modelling before installing the system.

(c)(i)

Define the term ‘performance modelling’.

Figure for question 2

[1]

(c)(ii)

Identify one way performance modelling could be used to test the new system.

Figure for question 2

[1]

(d)

Mary created the program as a series of sub-programs that can be reused.

Describe one benefit of Mary creating reusable program components.

Figure for question 2

[2]

Question 3

Figure for question 3
(a)

The graph in Fig. 3 is a visualisation of the problem.

(a)(i)

Identify one difference between a graph and a tree.

Figure for question 3

[1]

(a)(ii)

Explain how the graph is an abstraction of the problem.

Figure for question 3

[2]

(a)(iii)

Identify two advantages of using a visualisation such as the one shown in Fig. 3.

Question 3, shown as an image
Question 3, shown as an image

[2]

(b)

Demonstrate how Dijkstra’s algorithm would find the shortest path to the solution in Fig. 3.

Figure for question 3

maths symbol

[7]

(c)

* The creator of the puzzle has been told that the A* algorithm is more efficient at finding the shortest path because it uses heuristics.

Compare the performance of Dijkstra’s algorithm and the A* search algorithm, making reference to heuristics, to find the shortest path to the problem.

Figure for question 3

maths symbol

[9]

Question 4

A recursive function, generate, is shown.

Figure for question 4
(a)

Trace the algorithm to show the value returned when generate(7) is called. Show each step of your working.

Figure for question 4

maths symbol

[6]

(b)

The parameter, num1, is passed by value.

Explain why the parameter was passed by value instead of by reference.

Figure for question 4

[2]

(c)

* Parameters can be used to reduce the use of global variables.

Compare the use of parameters to global variables in recursive functions.

Figure for question 4

maths symbol

[9]

(d)

A student called Jason writes a recursive algorithm. The recursive algorithm uses more memory than if Jason had written it as an iterative algorithm.

Explain why the recursive algorithm uses more memory than the iterative algorithm.

Figure for question 4

maths symbol

[2]

Question 5

A computer program stores data input on a stack named dataItems. The stack has two sub-programs to add and remove data items from the stack. The stack is implemented as a 1D array, dataArray.

Figure for question 5

The current contents of dataItems are shown:

Figure for question 5
(b)

The main program asks a user to push or pop an item from the stack. If the user chooses ‘push’, the data item is added to the stack. If the user chooses “pop”, the next item is removed from the stack, multiplied by 3 and output.

The main program is shown:

Figure for question 5
(b)(i)

Before the sub-programs, push() and pop(), can add or remove items from the stack, a selection statement is used to decide if each action is possible.

Describe the decision that needs to be made in each sub-program and how this impacts the next process.

Question 5, shown as an image
Question 5, shown as an image

[4]

(b)(ii)

The algorithm does not work when the user enters "PUSH" or "Push". The algorithm needs to be changed in order to accept these inputs.

Identify the line number to be changed and state the change that should be made.

Question 5, shown as an image

[2]

(c)

The stack is implemented as a 1D array, dataArray.

Describe how a 1D array can be set up and used to push and pop items as a stack.

Figure for question 5

maths symbol

[3]

(d)

As an array, the data in dataArray is sorted and then searched for a specific value.

(d)(i)

The data in dataArray is sorted into ascending order using an insertion sort.

The current contents of dataArray are shown:

Figure for question 5

Show the steps of an insertion sort on the current contents of the array dataArray.

Figure for question 5

maths symbol

[5]

(d)(ii)

The array dataArray can now be searched using a binary search.

Describe the stages of a binary search on an array of size n.

Figure for question 5

maths symbol

[7]

(d)(iii)

The array has 50 items.

The function, searchItem(), performs a linear search for a data item.

Figure for question 5

Rewrite the function using a while loop.

Figure for question 5

maths symbol

[4]

Question 6

Kamran is writing a program to manipulate the data for a set of items.

For each item, the program needs to store:

• Item name (e.g. Box)

• Cost (e.g. 22.58)

• Date of arrival (e.g. 1/5/2018)

• Transferred (e.g. true)

The items are added to a queue for processing.

The queue is defined as a class, itemQueue.

Figure for question 6

The head attribute points to the first element in the queue. The tail attribute points to the next available space in the queue. The numItems attribute states how many items are currently in the queue.

(a)

The data about the items can be stored using either a record structure, or as objects of a class.

(a)(i)

Explain the similarities and differences between a record and a class.

Figure for question 6

maths symbol

[3]

(a)(ii)

Kamran chooses to use a record structure to store the data about the items.

Record structures may be declared using the following syntax:

Figure for question 6

Complete the pseudocode to declare a record called items.

Figure for question 6

[5]

(a)(iii)

New records may be created using the following syntax:

Figure for question 6

Write a programming statement to create a new item, using the identifier ‘box1’, with the item name “Box”, the cost 22.58, date of arrival 1/5/2018 and transferred true.

Figure for question 6

maths symbol

[3]

(b)

The array, theItems, stores the items in the queue. When the tail of the queue exceeds the last element in the array, it adds a new item to the first element if it is vacant.

For example, in the following queue, the next item to be added would be placed at index 0.

Index0123456789
ElementDataDataDataDataDataDataData
(b)(i)

Define the term ‘queue’.

Figure for question 6

maths symbol

[2]

(b)(ii)

The attributes in itemQueue are all declared as private.

Explain how a private attribute improves the integrity of the data.

Figure for question 6

maths symbol

[2]

(b)(iii)

The constructor method creates a new instance of itemQueue and sets the head, tail and numItems attributes to 0.

Write an algorithm, using pseudocode or program code, for the constructor including the initialisation for all attributes.

Figure for question 6

maths symbol

[2]

(b)(iv)

The enqueue method:

maths symbol takes as a parameter the item to insert in the queue

maths symbol checks if the queue is full

maths symbol reports an error and returns false if the queue is full

maths symbol does the following if the queue is not full: o adds the item to the array at the tail position and adjusts the pointer(s) o returns true

The attribute numItems stores the number of items currently in the queue.

Write an algorithm, using pseudocode or program code, for the enqueue method.

Figure for question 6

maths symbol

[6]

(b)(v)

Write a programming statement to declare an instance of itemQueue called myItems

Figure for question 6

[1]

(b)(vi)

Write a procedure, insertItems(), to ask the user to input the data for an item. The item is then added to the queue myItems. The user is continually asked to input data items until the queue is full.

Figure for question 6

maths symbol

[5]

(b)(vii)

When the main program ends, the items and the queue no longer exist.

Describe how Kamran could amend the program to make sure the items and queue still exist and are used the next time the program is run.

Figure for question 6

maths symbol

[2]

(c)

* Kamran wants to expand the program to allow it to handle up to 100,000,000 items and to allow him to search for data about items. Kamran is worried that the increase in the number of items will cause a decrease in the performance of the program. He decides to investigate the benefits of caching and concurrent processing.

Evaluate the use of caching and concurrent processing in this scenario and make a recommendation to Kamran.

Figure for question 6

maths symbol

[9]

The paper as printed

Spotted a mistake on this page?Report a problem