Question 2
AQA Computer Science June 2018 Paper 1AS6 marks
On the specification
- 2.1
- 3.4 Theory of computation
- 2.2
- 3.4 Theory of computation
Question text
2 The algorithm, represented using pseudo-code in Figure 1, describes a method to test whether an integer greater than 2 is prime or not. Figure 1 INPUT Number Root ← 1 WHILE (Root * Root) < Number Root ← Root + 1 ENDWHILE d ← 2 FactorFound ← FALSE WHILE (FactorFound = FALSE) AND (d <= Root) r ← Number MOD d IF r = 0 THEN FactorFound ← TRUE ENDIF d ← d + 1 ENDWHILE IF FactorFound = FALSE THEN OUTPUT "Prime" ELSE OUTPUT "Not prime" ENDIF The MOD operator calculates the remainder resulting from an integer division, for example, 10 MOD 3 = 1. 2.1 Complete Table 3 by hand-tracing the algorithm in Figure 1. Use 5 as the input value. You may not need to use all the rows in Table 3. Table 3 Number Root d FactorFound r Output Copy the contents of all the unshaded cells in Table 3 into your Electronic Answer Document. [3 marks] 2.2 Complete Table 4 by hand-tracing the algorithm in Figure 1. Use 25 as the input value. You may not need to use all the rows in Table 4. Table 4 Number Root d FactorFound r Output Copy the contents of all the unshaded cells in Table 4 into your Electronic Answer Document. [3 marks]