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 | |
|---|---|---|
| 1Found ← FALSE | AThe not found message is output inside the loop for every element that does not match, instead of once after the loop has checked all elements. | |
| 2IF Names[Index] = Target THEN | BIF Found = FALSE THEN OUTPUT "Not found" | |
| 3When a match is found, record its position by storing the loop counter in a variable | CPosition ← Index | |
| 4After the loop ends, if the flag is still FALSE, tell the user that the value is not in the array | DThe Found flag is set to TRUE before the loop and is never set inside it, so the program thinks the value was found even when it was not. | |
| 5FOR Index ← 1 TO 10 IF Scores[Index] = Target THEN Found ← TRUE ELSE OUTPUT "Not found" ENDIF NEXT Index | ECompare the current element with the wanted value to see if it is a match | |
| 6Found ← TRUE FOR Index ← 1 TO 10 IF Scores[Index] = Target THEN Position ← Index ENDIF NEXT Index | FSet a flag before the loop starts to show that the wanted value has not been found yet |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
linear search — A loop checks every element against the wanted value. On a match, set Found to TRUE and record the index. If Found is still FALSE at the end, OUTPUT a not found message.Found ← FALSE
FOR Index ← 1 TO 10
IF Marks[Index] = Target THENDECLARE Names : ARRAY[1:10] OF STRING
FOR Index ← 1 TO 10
IF Names[Index] = Target THENFOR Index ← 1 TO 10
IF Marks[Index] = Target THEN
Found ← TRUEIF Marks[Index] = Target THEN
Found ← TRUE
Position ← IndexIF Found = FALSE THEN
OUTPUT "Target not found"
ENDIF