Question 4(b)(iii) 2021 · May-June · Paper 43 · 6 marks
Reveal official mark-scheme answer
Official answer for Question 4
Part (b)
(iii)
Question 1
mark per bullet point
Question 6
- Outputting the data in the root node
- Check if left Pointer is/is not –1 …
- … recursive call left with left pointer as parameter, if not –1
- Check if right Pointer is/is not –1 …
- … recursive call right with right pointer as parameter, if not −1
- Output, left, right in correct order with
Show text version of question
Question 4
Part (b)
(iii)
Question 4
Chon creates a binary tree structure to store options that the user can select from a menu (M) in
his program.
M
Each node in the binary tree is stored using the following record structure:
TYPE node
leftPointer : INTEGER
data : STRING
rightPointer : INTEGER
ENDTYPE
The tree is stored as a 1D array, binaryTree. Null pointers are represented by –1.
(iii)
A pre-order traversal on the following tree would output M C A G R L W
M
The pre-order traversal can be written as a recursive procedure:
1. output the root node 2. follow the left pointer and repeat from step 1 3. follow the right pointer and repeat from step 1.
Complete the pseudocode recursive procedure preOrder().
PROCEDURE preOrder(BYVALUE rootPointer : INTEGER)
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
Question 13
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
ENDPROCEDURE
Question 14
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 9608_s21_qp_43.pdf
