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 Pass ← 1 TO n - 1 | AThe outer loop: it repeats the pass through the array n - 1 times | |
| 2FOR i ← 1 TO n - Pass | BThe outer loop runs to n instead of n - 1, so it does one pass too many | |
| 3Inside the inner loop, compare two neighbours and swap them if they are out of order | CThe NEXT statements are in the wrong order: the loops are not closed from the inside out | |
| 4Close the blocks in the right order: ENDIF first, then the inner NEXT, then the outer NEXT | D ENDIF NEXT i NEXT Pass | |
| 5FOR Pass ← 1 TO n FOR i ← 1 TO n - Pass IF Data[i] > Data[i + 1] THEN | EThe inner loop: it compares neighbours, and its bound shrinks after each pass | |
| 6 ENDIF NEXT Pass NEXT i | FIF Data[i] > Data[i + 1] THEN Temp ← Data[i] Data[i] ← Data[i + 1] Data[i + 1] ← Temp ENDIF |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
FOR Pass ← 1 TO n - 1 — Outer loop of a bubble sort: it runs n - 1 passes. Inside it, an inner FOR loop compares neighbours and swaps them if out of order, so the whole array ends up sorted.FOR Pass ← 1 TO n - 1
FOR i ← 1 TO n - Pass
IF List[i] > List[i + 1] THENFOR Pass ← 1 TO n - 1
FOR i ← 1 TO n - Pass
IF List[i] > List[i + 1] THENFOR i ← 1 TO n - Pass
IF List[i] > List[i + 1] THEN
Temp ← List[i]Temp ← List[i]
List[i] ← List[i + 1]
List[i + 1] ← Temp ENDIF
NEXT i
NEXT Pass