Past-paper question · 2017 May-June · Paper 41 · Q3

Question 3 2017 · May-June · Paper 41 · 7 marks

Original past-paper question for 3
Original past-paper question for 3
Reveal official mark-scheme answer Official mark-scheme answer for 3

Official answer for Question 3

✓
FUNCTION Find(BYVAL Name : STRING,

Question 7

✓
BYVAL Start : INTEGER,
✓
BYVAL Finish : INTEGER) RETURNS INTEGER
✓
// base case
✓
Finish < Start

Question 1

✓
IF
✓
THEN
✓
RETURN -1
✓
ELSE
✓
(Start + Finish) DIV 2
✓
Middle ←

Question 1

✓
NameList[Middle] = Name

Question 1

✓
IF
✓
THEN
✓
RETURN Middle

Question 1

✓
ELSE
✓
// general case
✓
NameList[Middle]

Question 1

✓
IF SearchItem >
✓
THEN
✓
Find(Name, Middle + 1, Finish) 1
✓
ELSE
✓
Find(Name, Start, Middle - 1)

Question 1

✓
ENDIF
✓
ENDIF
✓
ENDIF
✓
ENDFUNCTION
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s17_ms_41.pdf →

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

[7]

Question 8

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 9608_s17_qp_41.pdf

Keep practising this topic