Question 12

AQA Computer Science June 2023 Paper 1B (8525/1B)GCSE15 marks

On the specification

12.1
3.1 Fundamentals of algorithms3.2 Programming
12.2
3.1 Fundamentals of algorithms3.2 Programming
12.3
3.1 Fundamentals of algorithms
12.4
3.2 Programming
Question text

12.1 Figure 11 shows a binary search algorithm that has been programmed in Python. box Figure 11 animals = ["cat", "dog", "hippo", "llama", "ox", "rat", "tiger", "wolf"] animalToFind = input("What animal would you like to find? ") validAnimal = False start = 0 finish = len(animals) - 1 while validAnimal == False and start <= finish: mid = (start + finish) // 2 if animals[mid] == animalToFind: validAnimal = True elif animalToFind > animals[mid]: start = mid + 1 else: finish = mid - 1 print(validAnimal) Complete the trace table for the program in Figure 11 if the user input is wolf Part of the table has already been filled in. You may not need to use all the rows in the table. [4 marks] animalToFind validAnimal start finish mid wolf False 0 7 3 12.2 Figure 12 shows a line of Python code that creates a list of fruit names. box Figure 12 fruits = ["banana", "apple", "orange", "pear", "grape", "pineapple"] Extend the program in Figure 12. Your answer must be written in Python. The program should get the user to enter a word and perform a linear search on the list fruits to find if the word is in the list or not. The program should: • ask the user what word they would like to find • output the message True if the word is found • output the message False if the word is not found. You must write your own linear search routine and not use any built-in search function available in Python. You should use indentation as appropriate, meaningful variable name(s) and Python syntax in your answer. The answer grid below contains vertical lines to help you indent your code. [7 marks] fruits = ["banana", "apple", "orange", "pear", "grape", "pineapple"] 12.3 State why a binary search cannot be used on the list fruits [1 mark] 12.4 Figure 13 shows an algorithm, represented using pseudo-code, that should display box currency names in reverse alphabetical order, starting with yen. There are errors in the logic of the algorithm. • Line numbers are included but are not part of the algorithm. Figure 13 1 SUBROUTINE diffCurrencies(currencies) currencies  ['baht', 'dollar', 'euro', 2 'koruna', 'lira', 'rand', 'rupee', 'yen'] 3 RETURN currencies[x] 4 ENDSUBROUTINE 5 6 FOR i  8 TO 0 STEP 1 7 OUTPUT(diffCurrencies(i)) 8 ENDFOR Rewrite line 1 and line 6 from Figure 13 to make the algorithm work as intended. [3 marks] Line 1 Line 6