Question 3 2017 · May-June · Paper 41 · 7 marks
Reveal official mark-scheme answer
Official answer for Question 3
Question 7
Question 1
Question 1
Question 1
Question 1
Question 1
Question 1
Show text version of question
Question 3
NameList is a 1D array that stores a sorted list of names. A programmer declares the array in pseudocode as follows:
NameList : Array[0 : 100] OF STRING
The programmer wants to search the list using a binary search algorithm.
The programmer decides to write the search algorithm as a recursive function. The function, Find, takes three parameters:
- Name, the string to be searched for
- Start, the index of the first item in the list to be searched
- Finish, the index of the last item in the list to be searched
The function will return the position of the name in the list, or −1 if the name is not found.
Complete the pseudocode for the recursive function.
FUNCTION Find(BYVALUE Name : STRING, BYVALUE Start : INTEGER, BYVALUE Finish : INTEGER) RETURNS INTEGER
// base case
IF .............................................................................................................................................
THEN
RETURN −1
ELSE
Middle ..................................................................................................................
IF ................................................................................................................................
THEN
RETURN ...........................................................................................................
ELSE // general case
IF SearchItem > .........................................................................................
THEN
.............................................................................................................
ELSE
.............................................................................................................
ENDIF
ENDIF
ENDIF
ENDFUNCTION
Question 8
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 9608_s17_qp_41.pdf
