Question 5(a) 2021 · May-June · Paper 41 · 4 marks
Reveal official mark-scheme answer
Official answer for Question 5
Part (a)
Question 1
mark for both returns
Question 4
Show text version of question
Question 5
Part (a)
Question 5
A binary search algorithm searches for data in a sorted array.
Part (a)
The pseudocode function binarySearch()performs a binary search to find a given value in
the global array, dataArray. If the value is found, the function returns its index. If the value is not found, the function returns –1.
Complete the pseudocode for the function binarySearch().
FUNCTION binarySearch(BYVALUE upper, lower, searchValue : INTEGER) RETURNS INTEGER
DECLARE flag : INTEGER
DECLARE mid : INTEGER
flag -2
mid 0
WHILE flag <> -1
mid lower + ((upper − lower) …………………………………………)
IF upper < lower
THEN
RETURN …………………………………………
ELSE
IF dataArray(mid) < searchValue
THEN
………………………………………… …………………………………………
ELSE
IF dataArray(mid) > searchValue
THEN
………………………………………… …………………………………………
ELSE
RETURN …………………………………………
ENDIF
ENDIF
ENDIF
ENDWHILE
ENDFUNCTION
Question 15
Why this question appears here
82% assigned-topic match · Programming › Constructs
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 9608_s21_qp_41.pdf
