Question 4
AQA Computer Science Specimen Paper 1 (7517/1)A level10 marks
On the specification
- 4.1
- 4.3 Fundamentals of algorithms
- 4.2
- 4.3 Fundamentals of algorithms
- 4.3
- 4.3 Fundamentals of algorithms
- 4.4
- 4.4 Theory of computation
- 4.5
- 4.3 Fundamentals of algorithms4.4 Theory of computation
- 4.6
- 4.4 Theory of computation
- 4.7
- 4.3 Fundamentals of algorithms4.4 Theory of computation
- 4.8
- 4.3 Fundamentals of algorithms4.4 Theory of computation
Question text
4 Figure 5 shows an incomplete algorithm for a binary search. Figure 5 PROCEDURE BSearch(List, F, L, ItemToFind) Found False Failed (1) WHILE NOT Failed AND NOT Found M (F + L) DIV 2 IF List[M] = ItemToFind THEN Found True ELSE IF F >= L (2) ELSE IF List[M] > ItemToFind THEN (3) ELSE F M + 1 ENDIF ENDIF ENDIF ENDWHILE IF Found = True THEN OUTPUT "Item is in list" ELSE OUTPUT "Item is not in list" ENDIF ENDPROCEDURE The DIV operator calculates the whole number result of integer division. For example, 15 DIV 4 = 3, 17 DIV 4 = 4. 4.1 What code should be added at position (1) in Figure 5? [1 mark] 4.2 What code should be added at position (2) in Figure 5? [1 mark] 4.3 What code should be added at position (3) in Figure 5? [2 marks] Table 6 contains a list of orders of time complexity (in no particular order). Table 6 Order of time complexity O(1) 2 O(n ) O(log n) n O(k ) O(n) Which of the orders of time complexity given in Table 6: 4.4 could be the time complexity of an intractable problem? [1 mark] 4.5 is the time complexity for a binary search? [1 mark] 4.6 is the time complexity for getting the first item in a list? [1 mark] 4.7 is the time complexity for a linear-search algorithm? [1 mark] 4.8 Explain why a linear-search has the order of time complexity given in your answer to question 0 4 . 7 . [2 marks]