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 | |
|---|---|---|
| 1Index | Data[Index] | Found | AIF Data[Index] = Target THEN Found ← TRUE ENDIF | |
| 2Target = 9, row: 2 | 9 | TRUE | BThe column headings of a trace table for a linear search: the index, the element compared and the Found flag. | |
| 3Found changes to TRUE in the trace table only on the row where the element equals the target | CComparisons ← Comparisons + 1 | |
| 4To count comparisons, add 1 on every pass, so the Comparisons column goes up by one on each row | DThe trace table starts at index 0, but Cambridge arrays usually start at index 1. The first row should be 1 | Data[1] | FALSE. | |
| 5Data has indexes 1 to 5. First row: 0 | Data[0] | FALSE | EThe element compared (8) equals the target, so Found should be TRUE on this row, not FALSE. | |
| 6Target = 8. Row: 3 | 8 | FALSE | FOn the pass at index 2 the element 9 matched the target, so Found became TRUE. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
trace table — A table that records the index, the element compared and the Found flag on each pass of a linear search, so you can follow it step by step.Found ← FALSE
FOR Index ← 1 TO 5
IF List[Index] = Target THEN Found ← TRUEFOR Index ← 1 TO 5
IF List[Index] = Target THEN
Found ← TRUEFOR Index ← 1 TO 5
Comparisons ← Comparisons + 1
IF List[Index] = Target THEN Found ← TRUEIF Found = FALSE THEN
OUTPUT "Not found"
ENDIFFOR Index ← 1 TO 6
IF List[Index] = Target THEN
Matches ← Matches + 1