Question 10(b) 2024 · May-June · Paper 31 · 5 marks
Reveal official mark-scheme answer
Official answer for Question 10
Part (b)
Question 5
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
Question 11
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
