Question 1

AQA Computer Science June 2022 Paper 1 (7516/1)AS

On the specification

4.3 Fundamentals of algorithms3.2 Fundamentals of data structures
Question text

1 The algorithm, represented using pseudo-code in Figure 1, describes a method to access numbers in the data structure, List, shown in Table 1. Figure 1 SUBROUTINE A(S, X, Y) P ← -1 WHILE P = -1 AND X <= Y Z ← (X + Y) DIV 2 IF List[Z] = S THEN P ← Z ELSE IF List[Z] < S THEN X ← Z + 1 ELSE Y ← Z – 1 ENDIF ENDIF ENDWHILE RETURN P ENDSUBROUTINE The DIV operator calculates the whole number part resulting from an integer division, for example, 10 DIV 3 = 3 Complete Table 2 by hand-tracing the algorithm in Figure 1 when the following statement is executed. Result ← A(38, 0, 18) You may not need to use all the rows in Table 2. The first row of Table 2 has already been completed for you. Table 1 List [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18]