Six original Cambridge-style questions on binary search: conditions, trace tables, pseudocode and performance.
(Low + High) DIV 2; compare List[Mid] with the search item.Low ← Mid + 1; smaller means High ← Mid - 1.INT(log2 n) + 1 comparisons.Describe how a binary search finds an item in a 1D array, and state one condition that must be met before it can be used.
Names : ARRAY[1:9] holds Ade, Bo, Cy, Dev, Eva, Fin, Gus, Hal, Ivy. Complete a trace table (Low, High, Mid, Names[Mid]) for a binary search for Gus and state the index returned.
Using the same array, trace a binary search for Ali. State the final values of Low and High and the value returned.
Codes : ARRAY[0:99] OF STRING is a global array sorted into ascending order. Write pseudocode for a function FindCode(Target : STRING) RETURNS INTEGER that uses a binary search and returns the index of Target, or −1 if it is not present.
RETURNS INTEGER, matching ENDFUNCTION. ✓WHILE Low <= High (and not found). ✓Mid ← (Low + High) DIV 2 inside the loop. ✓Low ← Mid + 1; greater means High ← Mid - 1. ✓A sorted file of 6000 records is loaded into an array. Calculate the maximum number of comparisons needed by (a) a linear search (b) a binary search. Show your working for (b).
A list of 12 product codes is unsorted and is searched once a day. A student suggests sorting it so that a binary search can be used. Evaluate this suggestion.
Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.