Past-paper question · 2022 October-November · Paper 42 · Q3(d)

Question 3(d) 2022 · October-November · Paper 42 · 6 marks

Original past-paper question for 3(D)
Original past-paper question for 3(D)
Reveal official mark-scheme answer Official mark-scheme answer for 3(D)

Official answer for Question 3

Part (d)

Question 1

mark per point:

Question 6

✓
•
✓
function call (and end where appropriate) taking a parameter
✓
•
✓
checking if at start of queue//20 …
✓
•
✓
…returning the last value in the queue
✓
•
✓
(otherwise) adding return value to a total // adding value in queue before
✓
recursive call and using this in the recursive call …
✓
•
✓
recursive call with Start/pointer −1
✓
•
✓
returning the final total
✓
Example program code:
✓
Java
✓
public static Integer RecursiveOutput(Integer Start){
✓
if(Start == 0){
✓
return Queue[Start];
✓
}else{
✓
return Queue[Start] + RecursiveOutput(Start -1);
✓
}}
✓
Python
✓
def RecursiveOutput(Start):
✓
if(Start == 0):
✓
return Queue[Start]
✓
else:
✓
return Queue[Start] + RecursiveOutput(Start - 1)
✓
VB.NET
✓
Function RecursiveOutput(ByVal Start)
✓
If (Start = 0) Then
✓
Return Queue(Start)
✓
Else
✓
Return Queue(Start) + RecursiveOutput(Start - 1)
✓
End If
✓
End Function

Mark scheme 9618_w22_ms_42.pdf →

Show text version of question

Question 3

Part (d)

Question 3

A program uses a linear queue to store up to 100 integers.

Part (d)

The following iterative pseudocode function calculates the total of all the values stored in the

queue.

FUNCTION IterativeOutput(Start: INTEGER) RETURNS INTEGER

DECLARE Total : INTEGER

Total ←0 FOR Count ← Start - 1 TO HeadPointer STEP -1

Total ← Total + Queue[Count]

NEXT Count

RETURN Total

ENDFUNCTION

Rewrite the function as a recursive function using program code.

Save your program.

Copy and paste the program code into part 3(d) in the evidence document.

[6]
Topic relevance

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_42.pdf

Keep practising this topic