Figure 9 shows five pseudo-code algorithms, A to E. Each is meant to add up the five values stored in the array numbers. Some of them do not work.
Tick one row in each column A to E: does that algorithm total all five values, or not?
Our own questions on this topic, marked straight away, so you see what to revise. Free now.
Show model answerHide model answer
A B C D E
Totals the five values ✓ ✓
Does not total them ✓ ✓ ✓C loops to position 7, which is past the end of the array, and it skips position 0. D never starts, because total is 0 and the loop needs it above 0. E never changes x, so it never stops.
How the marks are earned
- Any three columns correct earns one mark.
- All five columns correct earns both marks.
- A column with more than one tick earns nothing for that column.
- A and B total the five values. C, D and E do not.
Why it scores
A and B visit all five positions, 0 to 4, and add each value. C, D and E each fail, as the next paragraph shows.
These are the reasons for the three ticks in the second row. Each algorithm fails to produce the correct total.
Revise Trace Tables