9618/31/M/J/25 question 4: worked solution (May/June 2025, paper 31)

Show as plain text

Cambridge A2 Level Computer Science 9618 · 19.1 Algorithms Worked solution from the Computational thinking and Problem-solving Paper 3 Advanced Theory booklet, Part 1 of 2. Q19 9618/31/M/J/25 original Q4 Structured · 7 marks Worked solution (a) Insert each number by comparing with the nodes from the root. Go left if smaller, right if larger. 6: 6 < 36, 6 < 12, 6 > 3, so right of 3. 15: 15 < 36, 15 > 12, so right of 12. 41: 41 > 36, 41 > 40, so right of 40. 66: 66 > 36, 66 > 40, 66 > 41, so right of 41. Node Left pointer Right pointer 36 arrow to 12 arrow to 40 12 arrow to 3 arrow to 15 40 -1 arrow to 41 3 -1 arrow to 6 6 -1 -1 15 -1 -1 41 -1 arrow to 66 66 -1 -1 Any two new nodes added correctly with correct data and arrows [1] The other two nodes added correctly, with all arrows starting from the pointer boxes [1] Correct -1 null pointers added throughout [1] No entries in the other pointer boxes and all nodes correctly placed and connected [1] (b) Say what recursion is, then when it stops. Recursion is a technique where a subroutine (function or procedure) calls itself to solve a problem [1] It keeps calling itself until the base case (terminating condition) is reached, when no more recursive calls are made [1] (c) Write one ADT. Stack [1] KEY IDEA Add a value to a binary tree by going left for smaller and right for larger until a null pointer is found. TOTAL 7 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by rjmcompsci. Tap the picture to open it on YouTube.