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 | |
|---|---|---|
| 1FOR Index ← 1 TO 10 IF Names[Index] = Target THEN Found ← TRUE | AThe average case is about half the list, around 50 checks. Only the best case needs 1 check. | |
| 2Found ← FALSE | BFOR Index ← 1 TO 10 | |
| 3Best case: the target is the very first item, so only 1 check is needed | CChecks each item in the list in turn, starting from the first, to see if it equals the target | |
| 4Worst case: the target is the last item or not in the list, so every item is checked | DA linear search works on unsorted data. It simply checks each item in turn, so no sorting is needed. | |
| 5Linear search needs the list to be sorted into order first, otherwise it cannot work | EStarts the search with the target not yet found; it only becomes TRUE if a matching item turns up | |
| 6On average, a linear search of 100 items needs 1 check to find the target | FNames[1] = Target |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
linear search — Checks each item in a list in turn, from the start, until the target is found or the end of the list is reached. It works on unsorted data.Target ← 7
Index ← 0
Found ← FALSE// Scores has 5 items (index 0 to 4)
FOR Index ← 0 TO 4FOR Index ← 0 TO 4
IF Scores[Index] = Target THEN
Found ← TRUEIF Scores[Index] = Target THEN
Found ← TRUE
ENDIF// Worst case: target is last or missing
// List has 5 items, so most checks is:
Checks ← 5