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 | |
|---|---|---|
| 1Swapped ← FALSE | AStop repeating the passes once a whole pass has made no swaps, so the data is sorted | |
| 2UNTIL Swapped = FALSE | BSwapped ← TRUE | |
| 3When two neighbouring values are out of order and get swapped, the flag must record that a swap happened | CWHILE Swapped = TRUE DO | |
| 4A WHILE version keeps looping as long as the last pass made a swap | DReset the flag at the start of each pass, assuming no swaps have happened yet | |
| 5REPEAT FOR i ← 1 TO 4 ... NEXT i Swapped ← FALSE UNTIL Swapped = FALSE | ESwapped is reset to FALSE after the pass instead of before it, so it erases any swap that was recorded and the loop always stops after one pass. | |
| 6IF Numbers[i] > Numbers[i + 1] THEN Temp ← Numbers[i] Numbers[i] ← Numbers[i + 1] Numbers[i + 1] ← Temp ENDIF | FSwapped ← TRUE is missing inside the IF, so the flag stays FALSE even when a swap happens and the sort may stop too early. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
UNTIL Swapped = FALSE — A BOOLEAN flag set to FALSE before each pass and to TRUE whenever a swap happens. The bubble sort stops when a full pass leaves it FALSE, meaning no swaps were needed and the data is sorted.REPEAT
Swapped ← FALSE
FOR i ← 1 TO 9IF Numbers[i] > Numbers[i + 1] THEN
Swapped ← TRUE
ENDIF NEXT i
UNTIL Swapped = FALSESwapped ← TRUE
WHILE Swapped = TRUE DO
Swapped ← FALSE// Sorted data: no swaps in pass 1
UNTIL Swapped = FALSE
OUTPUT "Done"