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 | |
|---|---|---|
| 15 3 8 1 → 3 5 1 8 | ASwapped ← TRUE | |
| 2Temp ← Numbers[i] | BThe array before and after pass 1 of a bubble sort on 5, 3, 8, 1. Adjacent pairs were compared, and the 8 reached the end. | |
| 3In a trace table, the Swapped column changes to TRUE on any comparison that causes a swap during a pass. | CFOR Index ← 1 TO 4 | |
| 4With 5 items, one pass makes 4 comparisons, so the trace has 4 comparison rows for each pass. | DThe Temp column holds the value copied out of the array just before a swap, so it is not lost when overwritten. | |
| 55 3 8 1 after pass 1: 1 3 5 8 | EA single pass only swaps neighbouring items, so it cannot fully sort the array. After pass 1 the array is 3 5 1 8. | |
| 6IF Numbers[i] >= Numbers[i + 1] THEN | FUsing >= swaps equal values for no reason. With duplicates, Swapped is set to TRUE even though nothing changes. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
bubble sort trace — Writing out the array after every pass, showing each comparison and swap, plus the Temp and Swapped values, to see how a bubble sort puts the data in order.IF Data[i] > Data[i + 1] THEN
// swap, equal values are left alone
ENDIFTemp ← Data[i]
Data[i] ← Data[i + 1]
Data[i + 1] ← TempIF Data[i] > Data[i + 1] THEN
Swapped ← TRUE
ENDIF// Data has 5 items
FOR i ← 1 TO 4
IF Data[i] > Data[i + 1] THENREPEAT
Swapped ← FALSE
FOR i ← 1 TO 4