Past-paper question · 2024 May-June · Paper 42 · Q3(d)(ii)

Question 3(d)(ii) 2024 · May-June · Paper 42 · 2 marks

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

Official answer for Question 3

Part (d)

(ii)

Question 1

mark each

Question 2

✓
Calling BinarySearch function with sorted array, 0, 6/len(array)–1, 644 as parameters
✓
Checking return value and outputting ‘Not found’ if –1 and index otherwise
✓
e.g.
✓
Java
✓
Position = BinarySearch(Sorted2Array, 0, 6, 644);
✓
if(Position == -1){
✓
System.out.println("Not found");
✓
}else{
✓
System.out.println(Position);
✓
}
✓
VB.NET
✓
Position = BinarySearch(Sorted2Array, 0, 6, 644)
✓
If Position = -1 Then
✓
Console.WriteLine("Not found")
✓
Else
✓
Console.WriteLine(Position)
✓
End If
✓
Python
✓
Position = BinarySearch(Sorted2Array, 0, len(NumberArray)-1, 644)
✓
if Position == -1:
✓
print("Not found")
✓
else:
✓
print(Position)
✓
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 (d)

(ii)

Question 3

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

The recursive function BinarySearch()takes the parameters:

  • IntegerArray – an array of integers
  • First – the index of the first array element
  • Last – the index of the last array element
  • ToFind – an integer to search for in the array.

The function uses recursion to perform a binary search for ToFind in IntegerArray. The function returns the index where ToFind is stored or returns −1 if ToFind is not in the array.

(ii)

Write program code to amend the main program to:

  • call BinarySearch()with the sorted array and the integer 644 as the search value
  • output ‘Not found’ if 644 is not found in the array
  • output the index if 644 is found in the array.

Save your program.

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

[2]
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