Past-paper question · 2024 May-June · Paper 42 · Q3(b)(i)

Question 3(b)(i) 2024 · May-June · Paper 42 · 4 marks

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

Official answer for Question 3

Part (b)

(i)

Question 1

mark each

Question 4

✓
Recursive function written with recursive call
✓
Correct base case and return
✓
Correct while loop control and internal
✓
All correct and structure followed
✓
e.g.
✓
Java
✓
public static Integer[] RecursiveInsertion(Integer[] IntegerArray, Integer NumberElements){
✓
Integer LastItem;
✓
Integer CheckItem;
✓
if(NumberElements <= 1){
✓
return IntegerArray;
✓
}else{
✓
RecursiveInsertion(IntegerArray, NumberElements - 1);
✓
LastItem = IntegerArray[NumberElements - 1];
✓
CheckItem = NumberElements - 2;
✓
}
✓
Boolean LoopAgain = true;
✓
if(CheckItem < 0){
✓
LoopAgain = false;
✓
}else if(IntegerArray[CheckItem] < LastItem){
✓
LoopAgain = false;
✓
}
✓
while(LoopAgain){
✓
IntegerArray[CheckItem + 1] = IntegerArray[CheckItem];
✓
CheckItem = CheckItem - 1;
✓
if(CheckItem < 0){
✓
LoopAgain = false;
✓
9618/42
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2024
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_s24_ms_42.pdf →

Show text version of question

Question 3

Part (b)

(i)

Question 3

A program sorts an array of integers and searches the array for a particular value.

(i)

The following recursive pseudocode function sorts the array into ascending order using

an insertion sort and returns the sorted array.

DECLARE LastItem : INTEGER DECLARE CheckItem : INTEGER DECLARE LoopAgain : BOOLEAN FUNCTION RecursiveInsertion(IntegerArray : ARRAY[] OF INTEGER, NumberElements : INTEGER) RETURNS ARRAY[] OF INTEGER IF NumberElements <= 1 THEN RETURN IntegerArray ELSE CALL RecursiveInsertion(IntegerArray, NumberElements - 1) LastItem IntegerArray[NumberElements - 1] CheckItem NumberElements - 2 ENDIF LoopAgain TRUE IF CheckItem < 0 THEN LoopAgain FALSE ELSE IF IntegerArray[CheckItem] < LastItem THEN LoopAgain FALSE ENDIF ENDIF WHILE LoopAgain IntegerArray[CheckItem + 1] IntegerArray[CheckItem] CheckItem CheckItem - 1 IF CheckItem < 0 THEN LoopAgain FALSE ELSE IF IntegerArray[CheckItem] < LastItem THEN LoopAgain FALSE ENDIF ENDIF ENDWHILE IntegerArray[CheckItem + 1] LastItem RETURN IntegerArray ENDFUNCTION

Write the program code for the pseudocode function RecursiveInsertion().

Save your program.

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

[4]

Question 12

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

Keep practising this topic