Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1mid ← (low + high) DIV 2 | AIF list[mid] < target THEN low ← mid + 1 | |
| 2low > high | BFinds the middle index of the current search range, rounding down to a whole number | |
| 3The target is greater than the middle item, so the search moves to the upper half of the range | CIF list[mid] > target THEN high ← mid - 1 | |
| 4The target is smaller than the middle item, so the search moves to the lower half of the range | DThe range is empty, so the target is not in the list and the search stops | |
| 5IF list[mid] < target THEN low ← mid | ELow should be set to mid + 1, not mid. Mid has already been checked, so the range may never shrink and the trace table repeats forever. | |
| 6Start: low ← 1, high ← 8, mid ← 4. Trace stops when low = high | FThe search should stop when low is greater than high, not when they are equal. When low equals high there is still one item left to check. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
mid ← (low + high) DIV 2 — Each row of a binary search trace table updates low, high and mid. The range halves each step until the target is found or low becomes greater than high.mid ← (low + high) DIV 2WHILE low ≤ high
mid ← (low + high) DIV 2IF list[mid] < target THEN
low ← mid + 1ELSE IF list[mid] > target THEN
high ← mid - 1IF low > high THEN
OUTPUT "Not found"