Skip to main content
A-LevelComputer ScienceData types and structures9618/41 · Oct/Nov 2022 · Q321 Marks

A binary tree consists of nodes. Each node has 3 integer values: a left pointer, data and a right pointer. The binary tree is stored using a global 2D array. The pseudocode declaration for the array is: DECLARE ArrayNodes : ARRAY[0:19, 0:2] OF INTEGER For example: • ArrayNodes[0, 0] stores the left pointer for the first node. • ArrayNodes[0, 1] stores the data for the first node. • ArrayNodes[0, 2] stores the right pointer for the first node. -1 indicates a null pointer, or null data.

  1. (a)Write program code to: • declare the global 2D array ArrayNodes • initialise all 3 integer values to -1 for each node.[3]
  2. (b)The binary tree stores the following values: Index | Left pointer | Data | Right pointer ---|---|---|--- 0 | 1 | 20 | 5 1 | 2 | 15 | -1 2 | -1 | 3 | 3 3 | -1 | 9 | 4 4 | -1 | 10 | -1 5 | -1 | 58 | -1 6 | -1 | -1 | -1 FreeNode stores the index of the first free element in the array, initialised to 6. RootPointer stores the index of the first node in the tree, initialised to 0. Amend your program by writing program code to store the given data in ArrayNodes and initialise the free node and root node pointers.[2]
  3. (c)The following recursive pseudocode function searches the binary tree for a given value. If the value is found, the function must return the index of the value. If the value is not found, the function must return -1. The function is incomplete. There are four incomplete statements. FUNCTION SearchValue (Root : INTEGER, ValueToFind : INTEGER) RETURNS INTEGER IF Root = -1 THEN RETURN -1 ELSE IF ArrayNodes [Root, 1] = ValueToFind THEN RETURN .......................... ELSE IF ArrayNodes[Root, 1] = -1 THEN RETURN -1 ENDIF ENDIF ENDIF IF ArrayNodes[Root, 1] ................... ValueToFind THEN RETURN SearchValue(ArrayNodes[............., 0], ValueToFind) ENDIF IF ArrayNodes[Root, ............] < ValueToFind THEN RETURN SearchValue(ArrayNodes[Root, 2], ValueToFind) ENDIF ENDFUNCTION Write program code for the function SearchValue().[5]
  4. (d)A post order traversal performs the following operation: • visit the left node • visit the right node • output the root. For example, in the following tree, the output would be: 3 9 25 60 50 [Figure X.X] An outline of the PostOrder() procedure is: • If left node is not empty, make a recursive call with the left node as the root. • If right node is not empty, make a recursive call with the right node as the root. • Output the current root node. The procedure PostOrder () takes the root node as a parameter. Write program code for the procedure PostOrder().[7]
  5. (e)(i)Amend the main program by writing program code to: • call the function SearchValue() to find the position of the number 15 in the tree • use the result from SearchValue() to output either the index of the value if found, or an appropriate message to state that the value was not found • call the procedure PostOrder().[3]
  6. (e)(ii)Test your program. Take a screenshot to show the output. Copy and paste the screenshot into part 3(e)(ii) in the evidence document.[1]

This question uses a diagram from the original paper, which isn't shown here. Open the full paper from the past papers archive to see it.

Mark scheme

Marking points from the official mark scheme (Oct/Nov 2022). The mark or mark type is shown in brackets.

  1. 1 mark per point:
  2. [1] Declaring (global) 2D array ArrayNodes
  3. [1] looping through all 20 × 3 elements of array
  4. [1] storing -1 in each element
  5. 1 mark per point:
  6. [1] initialising each of the first 6 array elements correctly
  7. [1] declaring and initialising FreeNode to 6 and RootPointer to 0
  8. [1] 1 mark for each completed statement (4)
  9. [1] 1 mark for remainder of function correct
  10. 1 mark per point (Max 7):
  11. [1] (procedure) header (and end where appropriate) with one parameter (root node or index of root node) and at least one recursive call
  12. [1] checking if left node is -1
  13. [1] ...if not recursive call with parameter as ArrayNodes[RootNode[0]]
  14. [1] checking if right node is -1
  15. [1] ...if not recursive call with parameter as ArrayNodes[RootNode[2]]
  16. [1] outputting the element at the parameter RootNode[]
  17. [1] all 3 in the correct order
  18. 1 mark per point:
  19. [1] calling SearchValue() with 15 and rootPointer as a parameter ...
  20. [1] if return value > -1 output returned index and if return value = -1 output not found Both as appropriate messages
  21. [1] Calling PostOrder() with ArrayNodes[RootPointer] as a parameter
  22. [1] Screenshot with result as shown, for example: Found at 1 10 9 3 15 58 20

Write your answer and get it marked

On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.

Sign up free →

About this question

Topic
Data types and structures, A-Level Computer Science (syllabus 9618). Structured question, 21 marks.
Source
A-Level Computer Science, Oct/Nov 2022 Paper 4 Variant 1, question 3.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep