Question 3(c) 2022 · October-November · Paper 43 · 5 marks
Question 3
Part (c)
Question 3
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.
Part (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().
Save your program.
Copy and paste the program code into part 3(c) in the evidence document.
Question 10
Reveal official mark-scheme answer

Official answer for Question 3
Part (c)
Question 1
mark for each completed statement (4)
Question 5
Why this question appears here
98% assigned-topic match · Computational thinking and problem-solving › Recursion
Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.
Permanent source page: Educate A Change · From 9618_w22_qp_43.pdf
