Question 1
OCR Computer Science June 2018 Paper 2A level13 marks
On the specification
- (a)
- 1.4 Data types, data structures and algorithms
- (b)
- 1.4 Data types, data structures and algorithms2.3 Algorithms
- (c)(i)
- 2.2 Problem solving and programming2.3 Algorithms
- (c)(ii)
- 2.1 Elements of computational thinking1.4 Data types, data structures and algorithms
Question text
1 A program stores entered data in a binary search tree. The current contents of the tree are shown: Italy France Spain Austria Germany Norway (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. Italy France Spain Austria Germany Norway [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. The function currentNode.right()returns the node positioned to the right of currentNode. function searchForData(currentNode:byVal, searchValue:byVal) thisNode = getData( ) if thisNode == then return elseif thisNode < searchValue then if currentNode.left() != null then return (searchForData(currentNode.left(), searchValue)) else return endif else if != null then return (searchForData(currentNode.right(), searchValue)) else return false endif endif endfunction (i) Complete the algorithm. [5] (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. 1 2 [2]