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 | |
|---|---|---|
| 1Temp ← Item[i] Item[i] ← Item[i + 1] Item[i + 1] ← Temp | ASwaps two neighbouring elements by holding one value in a temporary variable first | |
| 2IF Item[i] > Item[i + 1] THEN | BCompares two neighbouring elements and checks whether they are in the wrong order for an ascending sort | |
| 3The inner loop visits every neighbouring pair in one pass, so it stops one place before the end of the array | CFOR i ← 1 TO Count - 1 | |
| 4The outer loop repeats passes until a pass makes no swaps, using a flag to record whether a swap happened | DThe loop goes up to Count, so on the last pass Item[i + 1] is outside the array. The loop should end at Count - 1. | |
| 5Item[i] ← Item[i + 1] Item[i + 1] ← Item[i] | EREPEAT Swapped ← FALSE // inner loop pass UNTIL Swapped = FALSE | |
| 6FOR i ← 1 TO Count IF Item[i] > Item[i + 1] THEN | FNo Temp variable is used, so Item[i] is overwritten and both elements end up with the same value. The original Item[i] is lost. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
bubble sort — A sort that makes repeated passes, comparing neighbouring items and swapping them using a Temp variable if they are in the wrong order, until a pass makes no swaps.Temp ← Item[i]
Item[i] ← Item[i + 1]
Item[i + 1] ← TempIF Item[i] > Item[i + 1] THEN
// swap the two items
ENDIFFOR i ← 1 TO 9
// compare Item[i] and Item[i + 1]
NEXT iREPEAT
// inner loop makes one pass
UNTIL Swapped = FALSEIF Item[i] > Item[i + 1] THEN
Swapped ← TRUE
ENDIF