Past-paper question · 2021 May-June · Paper 43 · Q5(b)

Question 5(b) 2021 · May-June · Paper 43 · 5 marks

Original past-paper question for 5(B)
Original past-paper question for 5(B)
Reveal official mark-scheme answer Official mark-scheme answer for 5(B)

Official answer for Question 5

Part (b)

Question 1

mark per bullet point

Question 5

  • If search value is greater, then recursive call…
  • …with the mid + 1 sent in place as lower (and other correct parameters)
  • If search value is less than recursive call…
  • …with the mid − 1 sent in place as upper (and other correct parameters)
  • Return −1 when not found AND Return mid when found
✓
Example code:
✓
VB.NET
✓
Function recursiveBinarySearch(ByVal lowerbound, ByVal upperbound, ByVal searchValue)
✓
Dim mid As Integer = 0
✓
mid = lowerbound + ((upperbound - lowerbound) \ 2)
✓
If upperbound < lowerbound Then
✓
Return -1
✓
Else
✓
If dataArray(mid) < searchValue Then
✓
Return recursivebinarySearch(mid + 1, upperbound, searchValue)
✓
ElseIf dataArray(mid) > searchValue Then
✓
Return recursivebinarySearch(lowerbound, mid - 1, searchValue)
✓
Else
✓
Return mid
✓
End If
✓
End If
✓
End Function
✓
9608/43
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2021
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s21_ms_43.pdf →

Show text version of question

Question 5

Part (b)

Question 5

A binary search algorithm searches for data in a sorted array.

Part (b)

The binary search algorithm can be written recursively.

Write program code for a recursive function recursiveBinarySearch().

Programming language ............................................................................................................

Program code

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

.............................................................................................................................................

[5]

Question 16

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_s21_qp_43.pdf

Keep practising this topic