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 | |
|---|---|---|
| 1IF Marks[Index] > Marks[Index + 1] THEN | AIF Marks[Index] < Marks[Index + 1] THEN | |
| 2FOR Index ← 1 TO n - 1 | BThere is no temporary variable, so the first assignment overwrites Marks[Index] and both items end up with the same value. Use Temp to hold one value first. | |
| 3To sort into descending order, change the comparison so the swap happens when the first item is smaller than its neighbour | CLoops so that Index + 1 never goes past the last item in the array | |
| 4The swap must be inside the IF, so it only happens when the pair is in the wrong order | DIF Marks[Index] > Marks[Index + 1] THEN Temp ← Marks[Index] Marks[Index] ← Marks[Index + 1] Marks[Index + 1] ← Temp ENDIF | |
| 5FOR Index ← 1 TO n IF Marks[Index] > Marks[Index + 1] THEN | ECompares an item with its neighbour and runs the swap only if the first is larger than the second | |
| 6IF Marks[Index] > Marks[Index + 1] THEN Marks[Index] ← Marks[Index + 1] Marks[Index + 1] ← Marks[Index] ENDIF | FThe loop goes up to n, so on the last turn Marks[Index + 1] is outside the array and causes an error. The upper bound should be n - 1. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
IF Marks[Index] > Marks[Index + 1] THEN — One pass: a FOR loop compares each item with its neighbour and swaps them if the first is larger, so the biggest value moves to the end.FOR Index ← 1 TO 4
IF Marks[Index] > Marks[Index + 1] THEN
ENDIFFOR Index ← 1 TO n - 1
IF Marks[Index] > Marks[Index + 1] THEN
ENDIFTemp ← Marks[Index]
Marks[Index] ← Marks[Index + 1]
Marks[Index + 1] ← TempIF Marks[Index] < Marks[Index + 1] THEN
Temp ← Marks[Index]
Marks[Index] ← Marks[Index + 1]Marks[Index] ← Marks[Index + 1]
Marks[Index + 1] ← Temp
ENDIF