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 | |
|---|---|---|
| 1WHILE Index <= 10 AND Found = FALSE DO | ACompares the current array element with the value being searched for | |
| 2IF Item[Index] = Target THEN | BFound ← TRUE | |
| 3A BOOLEAN found flag starts as FALSE and is set to TRUE when the target is matched | CIndex is never increased inside the loop, so the same element is checked forever. Add Index ← Index + 1 inside the loop. | |
| 4If the loop ends and the flag is still FALSE, tell the user the target was not found | DIF Found = FALSE THEN OUTPUT "Not found" ENDIF | |
| 5IF Item[Index] ← Target THEN | EKeeps searching only while elements remain and no match has been found, so the search stops early | |
| 6Index ← 1 WHILE Index <= 10 AND Found = FALSE DO IF Item[Index] = Target THEN Found ← TRUE ENDIF ENDWHILE | FUses the assignment arrow ← instead of = to compare. It should be IF Item[Index] = Target THEN. |
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 array element in order from the first, comparing it with the target, until a match is found or the end of the array is reached.Found ← FALSE
Index ← 1
WHILE Index <= 10 AND Found = FALSE DOIndex ← 1
WHILE Index <= 10 AND Found = FALSE DO
IF Item[Index] = Target THENWHILE Index <= 10 AND Found = FALSE DO
IF Item[Index] = Target THEN
Found ← TRUE Index ← Index + 1
ENDWHILE
IF Found = FALSE THENIF Found = FALSE THEN
OUTPUT "Not found"
ENDIF