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 ← Marks[Index] | ACopies the saved value from Temp into the next element, finishing the swap | |
| 2Marks[Index + 1] ← Temp | BTemp is assigned after Marks[Index] has already been overwritten, so Temp saves the wrong value and the original is lost. | |
| 3The middle step of a swap copies the next element into the current one, which is safe because the old value is already in Temp | CMarks[Index] ← Marks[Index + 1] | |
| 4A complete swap of two neighbouring array elements uses three assignments in the correct order | DSaves the value in Marks[Index] in Temp so it is not lost when that element is overwritten | |
| 5Marks[Index] ← Marks[Index + 1] Marks[Index + 1] ← Marks[Index] | ETemp ← Marks[Index] Marks[Index] ← Marks[Index + 1] Marks[Index + 1] ← Temp | |
| 6Marks[Index] ← Marks[Index + 1] Temp ← Marks[Index] Marks[Index + 1] ← Temp | FThere is no temporary variable. After the first line both elements hold the same value, because the original Marks[Index] was overwritten and lost. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
Temp ← Marks[Index] — Saves the value of Marks[Index] in Temp so it is not lost. Marks[Index] can then be overwritten, and Temp is copied into Marks[Index + 1] to finish the swap.Temp ← Marks[Index]
Marks[Index] ← Marks[Index + 1]
Marks[Index + 1] ← TempTemp ← Marks[Index]
Marks[Index] ← Marks[Index + 1]
Marks[Index + 1] ← TempTemp ← Marks[Index]
Marks[Index] ← Marks[Index + 1]
Marks[Index + 1] ← TempTemp ← Marks[Index]
Marks[Index] ← Marks[Index + 1]
Marks[Index + 1] ← TempTemp ← Marks[Index]
Marks[Index] ← Marks[Index + 1]
Marks[Index + 1] ← Temp