Question 4

AQA Computer Science June 2017 Paper 1A level5 marks

On the specification

4.1
4.1 Fundamentals of programming
4.2
4.1 Fundamentals of programming
4.3
4.1 Fundamentals of programming4.3 Fundamentals of algorithms
Question text

4 Figure 4 shows the data Norbert, Phil, Judith, Mary, Caspar and Tahir entered into a binary search tree. Figure 5 contains pseudo-code for a recursive binary tree search algorithm. Figure 4 Norbert Judith Phil Caspar Mary Tahir Figure 5 FUNCTION TreeSearch(target, node) OUTPUT 'Visited ', node IF target = node THEN RETURN True ELSE IF target > node AND Exists(node, right) THEN RETURN TreeSearch(target, node.right) ELSE IF target < node AND Exists(node, left) THEN RETURN TreeSearch(target, node.left) ENDIF RETURN False ENDFUNCTION The subroutine Exists takes two parameters – a node in the binary tree and a direction (left or right). It returns a Boolean value indicating if the node given as a parameter has a child node in the direction specified by the second parameter. For instance, Exists(Mary, left) will return a value of False as there is no node to the left of Mary in the binary tree. node.right evaluates to the child node to the right of node, eg Judith.right is Mary. node.left evaluates to the child node to the left of node, eg Judith.left is Caspar. 4.1 What is meant by a recursive subroutine? [1 mark] 4.2 There are two base cases for the subroutine TreeSearch. State one of the base cases. [1 mark] 4.3 Complete the unshaded cells of Table 3 to show the result of tracing the TreeSearch algorithm shown in Figure 5 with the function call TreeSearch(Olivia, Norbert). You may not need to use all of the rows. [3 marks] Table 3 Function call Output TreeSearch(Olivia, Norbert) Copy the contents of the unshaded cells in Table 3 into the table in your Electronic Answer Document.