Question 12

AQA Computer Science June 2023 Paper 1C (8525/1C)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 VB.NET. box Figure 11 Dim animals As string() = {"cat", "dog", "hippo", "llama", "ox", "rat", "tiger", "wolf"} Console.Write("What animal would you like to find? ") Dim animalToFind As string = Console.ReadLine() Dim validAnimal As Boolean = False Dim start As Integer = 0 Dim finish As Integer = animals.Length - 1 While validAnimal = False And start <= finish Dim mid As Integer = (start + finish) \ 2 If animals(mid) = animalToFind Then validAnimal = True ElseIf animalToFind > animals(mid) Then start = mid + 1 Else finish = mid - 1 End If End While Console.WriteLine(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 VB.NET code that creates an array of fruit names. box Figure 12 Dim fruits() As String = {"banana", "apple", "orange", "pear", "grape", "pineapple"} Extend the program in Figure 12. Your answer must be written in VB.NET. The program should get the user to enter a word and perform a linear search on the array fruits to find if the word is in the array 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 VB.NET. You should use meaningful variable name(s) and VB.NET syntax in your answer. The answer grid below contains vertical lines to help you indent your code. [7 marks] Dim fruits() As String = {"banana", "apple", "orange", "pear", "grape", "pineapple"} 12.3 State why a binary search cannot be used on the array 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