Question 3(d)(ii) 2024 · May-June · Paper 42 · 2 marks
Reveal official mark-scheme answer
Official answer for Question 3
Part (d)
(ii)
Question 1
mark each
Question 2
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.
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
