Past-paper question · 2024 May-June · Paper 31 · Q10(b)

Question 10(b) 2024 · May-June · Paper 31 · 5 marks

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

Official answer for Question 10

Part (b)

✓
One mark for each correctly completed line (Max 5)

Question 5

✓
DECLARE Names : ARRAY[1:100000] OF STRING
✓
DECLARE TopOfList : INTEGER
✓
DECLARE EndOfList : INTEGER
✓
DECLARE CurrentItem : INTEGER
✓
DECLARE ToFind : STRING
✓
DECLARE Found : BOOLEAN
✓
DECLARE NotInList : BOOLEAN
✓
TopOfList 1
✓
EndOfList 100000
✓
OUTPUT "Which name do you wish to find? "
✓
INPUT ToFind
✓
Found FALSE
✓
NotInList FALSE
✓
WHILE Found = FALSE AND NotInList = FALSE
✓
CurrentItem (TopOfList + EndOfList) DIV 2
✓
IF ToFind = Names[CurrentItem]// Names[CurrentItem] = ToFind THEN
✓
Found TRUE
✓
ELSE
✓
IF TopOfList >= EndOfList THEN
✓
NotInList TRUE
✓
ELSE
✓
IF ToFind > Names[CurrentItem] THEN
✓
TopOfList CurrentItem + 1
✓
ELSE
✓
EndOfList CurrentItem – 1
✓
ENDIF
✓
ENDIF
✓
ENDIF
✓
ENDWHILE
✓
9618/31
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2024
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_s24_ms_31.pdf →

Show text version of question

Question 10

Part (b)

Part (b)

Complete the given pseudocode to find an item in a 1D array Names of type STRING using a

binary search.

DECLARE Names : ARRAY[1:100000] OF STRING DECLARE TopOfList : INTEGER DECLARE EndOfList : INTEGER DECLARE CurrentItem : INTEGER DECLARE ToFind : STRING DECLARE Found : BOOLEAN DECLARE NotInList : BOOLEAN TopOfList 1 ← EndOfList 100000 ← OUTPUT "Which name do you wish to find? " INPUT ToFind

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

NotInList ← FALSE WHILE ................................................ AND ................................................ CurrentItem ← (TopOfList + EndOfList) DIV 2

IF ........................................................................................................... THEN Found ← TRUE ELSE IF TopOfList >= EndOfList THEN

........................................................................................................... ELSE IF ToFind > Names[CurrentItem] THEN

........................................................................................................... ELSE EndOfList ← CurrentItem – 1 ENDIF ENDIF ENDIF ENDWHILE IF Found = TRUE THEN OUTPUT "Item found at position ", CurrentItem, " in array" ELSE OUTPUT "Item not in array" ENDIF

[5]

Question 11

Topic relevance

Why this question appears here

82% assigned-topic match · Data types and structures › Data types and records

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

Keep practising this topic