Skip to main content
A-LevelComputer ScienceFurther programming9618/41 · May/June 2025 · Q330 Marks

A program stores data in a binary tree that is designed using Object-Oriented Programming (OOP). The tree stores data in ascending numerical order, for example: [Diagram of a binary tree]. The class Node stores data about the nodes. NodeData : Integer stores the node's integer data LeftNode : Node stores the node that is stored to the left of the current node, or a null value if there is no node to the left RightNode : Node stores the node that is stored to the right of the current node, or a null value if there is no node to the right Constructor() initialises NodeData to its parameter value; initialises LeftNode and RightNode to a null value GetLeft() returns LeftNode GetRight() returns RightNode GetData() returns NodeData SetLeft() takes an object of type Node as a parameter and stores it in LeftNode SetRight() takes an object of type Node as a parameter and stores it in RightNode

  1. (a)(i)Write program code to declare the class Node and its constructor. Do not declare the other methods. Use your programming language appropriate constructor. If you are writing in Python, include attribute declarations using comments.[4]
  2. (a)(ii)Write program code for the three get methods.[3]
  3. (a)(iii)The method SetLeft() takes an object of type Node as a parameter. The method stores the parameter in the attribute LeftNode The method SetRight() takes an object of type Node as a parameter. The method stores the parameter in the attribute RightNode Write program code for SetLeft() and SetRight()[3]
  4. (b)Write the main program to declare five objects of type Node : • Node 1 with the data 10 • Node 2 with the data 20 • Node 3 with the data 5 • Node 4 with the data 15 • Node 5 with the data 7[2]
  5. (c)(i)Write program code to declare the class Tree and its constructor. Do not declare the other methods. Use your programming language appropriate constructor. If you are writing in Python, include attribute declarations using comments.[2]
  6. (c)(ii)Write program code for GetRootNode()[1]
  7. (c)(iii)The method Insert() takes a node as a parameter and then searches the tree to find the position to insert the new node by: • checking whether the node's data is less than or greater than the root node's data • moving to the left node if the data is less than the root node's data • moving to the right node if the data is greater than or equal to the root node's data • repeating until the final position of the node is found and stores the node in that position. Write program code for Insert()[6]
  8. (d)The recursive procedure OutputInOrder() outputs the data stored in the binary tree in ascending numerical order. The procedure takes a Node object as a parameter and then: • checks if the left node is null. If there is a left node, the function calls itself with the left node • outputs the data of the current node • checks if the right node is null. If there is a right node, the function calls itself with the right node. Write program code for OutputInOrder()[5]
  9. (e)(i)Write program code to extend the main program to: • create a new object of type Tree with the node containing the data 10 as the first node • insert the nodes with the values 20, 5, 15 and 7 into the tree in the order given • call OutputInOrder() with the tree's root node as a parameter.[3]
  10. (e)(ii)Test your program. Take a screenshot of the output(s). 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 (May/June 2025). The mark or mark type is shown in brackets.

  1. [4] 1 mark each
  2. [4] • Class header (and end where appropriate)
  3. [4] • Constructor header (and end where appropriate) with (min) one parameter (integer) within class
  4. [4] • 3 attributes with correct data types
  5. [4] • NodeData has parameter assigned, LeftNode and RightNode are assigned null within constructor
  6. [3] 1 mark each
  7. [3] • 1 get method with no parameter ...
  8. [3] ... returning correct value
  9. [3] • 2nd and 3rd correct get methods
  10. [3] 1 mark each
  11. [3] • 1 set method taking parameter of type Node ...
  12. [3] ... assigning to correct attribute
  13. [3] • 2nd correct set method
  14. [2] 1 mark each
  15. [2] • Creating 1 instance of Node with a correct value and storing the node ...
  16. [2] ... remaining 4 correct
  17. [2] 1 mark each
  18. [2] • Class Tree header (and end) no inheritance and constructor header (and end) taking 1 node parameter within class
  19. [2] • storing parameter in FirstNode declared as a Node data type
  20. [1] 1 mark for
  21. [1] • Get method header (and end) with no parameter, returning FirstNode
  22. [6] 1 mark each to max 6
  23. [6] • Insert method header (and end) taking 1 node parameter
  24. [6] • If parameter < first node, checking if there is a left node ...
  25. [6] ... storing node in left node if it is null
  26. [6] • If parameter >= first node, checking if there is a right node ...
  27. [6] ... storing node in right node if it is null
  28. [6] • Looping until correct position is found // recursive calls
  29. [5] 1 mark each
  30. [5] • Procedure header (and end) taking node as parameter, that is recursive
  31. [5] • Checking if left is null and recursive call if not null
  32. [5] • Outputting node's data
  33. [5] • Checking if right is null and recursive call if not null
  34. [5] • Correct order
  35. [3] 1 mark each
  36. [3] • Creation of Tree object with the Node with value 10 as parameter
  37. [3] • Calling method Insert() for tree with the nodes for 20, 5, 15 and 7 in order
  38. [3] • Calling OutputInOrder() with tree's root node as parameter
  39. [1] Output of
  40. [1] 5
  41. [1] 7
  42. [1] 10
  43. [1] 15
  44. [1] 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
Further programming, A-Level Computer Science (syllabus 9618). Structured question, 30 marks.
Source
A-Level Computer Science, May/June 2025 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