Past-paper question · 2025 May-June · Paper 43 · Q2(e)

Question 2(e) 2025 · May-June · Paper 43 · 6 marks

Question 2

Part (e)

Question 2

A program sorts the data in the 1D array DataArray and searches DataArray for specific

values.

DataArray stores 14 integer values and is declared local to the main program.

Part (e)

The function Search() performs a binary search to find ItemToFind in DataArray

The function takes two parameters:

  • DataArray, an array of integers
  • ItemToFind, an integer to find in DataArray

The function returns:

  • the index of ItemToFind if it is in DataArray
  • –1 if ItemToFind is not in DataArray

Write program code for Search()

You must not use any inbuilt searching functions for your programming language.

Save your program.

Copy and paste the program code into part 2(e) in the evidence document.

[6]

Question 6

Reveal official mark-scheme answer Official mark-scheme answer for 2(E)Official mark-scheme answer for 2(E)Official mark-scheme answer for 2(E)

Official answer for Question 2

Part (e)

Question 1

mark each

Question 6

  • Search() header (and close) taking array and integer as parameters
  • Looping/recursive calls until no elements left/Low<=High and returning –1 if not found
  • … calculating middle index and accessing this value
  • … comparison of array at middle value to integer parameter
  • … if they are equal return mid
✓
•
✓
… if array[mid] < parameter update low to middle + 1, if array[mid] > parameter update high to middle – 1 // recursive
✓
call with updated low and updated high
✓
9618/43
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
Example program code:
✓
Python
✓
def Search(DataArray, ItemToFind):
✓
Low = 0
✓
High = len(DataArray) - 1
✓
Middle = 0
✓
while Low <= High:
✓
Middle = (High + Low) // 2
✓
if DataArray[Middle] < ItemToFind:
✓
Low = Middle + 1
✓
elif DataArray[Middle] > ItemToFind:
✓
High = Middle - 1
✓
else:
✓
return Middle
✓
return -1
✓
Java
✓
public static Integer Search(Integer[] DataArray, Integer ItemToFind){
✓
Integer Low = 0;
✓
Integer High = DataArray.length - 1;
✓
Integer Middle = 0;
✓
while(Low <= High){
✓
Middle = (High + Low) / 2;
✓
if(DataArray[Middle] < ItemToFind){
✓
Low = Middle + 1;
✓
}else if(DataArray[Middle] > ItemToFind){
✓
High = Middle - 1;
✓
}else{
✓
return Middle;
✓
}
✓
}
✓
return -1;
✓
}
✓
9618/43
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
VB.NET
✓
Function Search(DataArray, ItemToFind)
✓
Dim Low As Integer = 0
✓
Dim High As Integer = DataArray.length() - 1
✓
Dim Middle As Integer = 0
✓
While Low <= High
✓
Middle = (High + Low) \ 2
✓
If DataArray(Middle) < ItemToFind Then
✓
Low = Middle + 1
✓
ElseIf DataArray(Middle) > ItemToFind Then
✓
High = Middle - 1
✓
Else
✓
Return Middle
✓
End If
✓
End While
✓
Return -1
✓
End Function
✓
9618/43
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_s25_ms_43.pdf →

Topic relevance

Why this question appears here

60% 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_s25_qp_43.pdf

Keep practising this topic