Question 2

AQA Computer Science November 2020 Paper 1 (7516/1)AS5 marks

On the specification

2.1
3.4 Theory of computation
2.2
3.4 Theory of computation
Question text

2 A sentinel value is a special value after the end of a series of data values. It is a terminator for the series of data values but is not treated as part of the series. A sentinel value is used when you do not know how many data values are in the series. The algorithm, represented using pseudo-code in Figure 1, is an attempt at a method to add numbers that are input as a series terminated by the sentinel value -1 Figure 1 X ← 0 Result ← 0 WHILE X ≠ -1 INPUT X Result ← Result + X ENDWHILE OUTPUT Result 2.1 Complete Table 1 by hand-tracing the algorithm in Figure 1. You may not need to use all the rows in Table 1. The first row of Table 1 has already been completed for you. The sequence of numbers for input is: 4, 6, 3, 2, -1 Table 1 X Result Output 0 - Copy the contents of all the unshaded cells in Table 1 into your Electronic Answer Document. [3 marks] 2.2 Comment on the result of the trace and describe how the algorithm should be modified. [2 marks]