Question 5
OCR Computer Science June 2025 Algorithms and problem solving (H046-02)AS14 marks
On the specification
- (a)
- 2.2 Problem solving and programming
- (b)
- 2.2 Problem solving and programming
- (c)
- 1.4 Data types, data structures and algorithms
- (d)(i)
- 2.3 Algorithms
- (d)(ii)
- 2.3 Algorithms
Question text
5 A programmer has been given this pseudocode algorithm. 1 do 2 data = input("Enter the code") 3 until data.length > 20 4 first = data.substring(0,1) 5 second = data.substring(1,1) 6 first = int(first) 7 second = int(second) 8 if first > second then 9 print(str(first) + "wins") 10 elseif first == second then 11 print("It's a draw") 12 else 13 print(second + "wins") 14 endif The pseudocode algorithm calls different subroutines. (a) Identify two subroutines that are called in the pseudocode algorithm. 1 2 [2] (b) Name the programming constructs that start on line 01 and line 08 in the pseudocode algorithm. 1 8 [2] (c) State the purpose of line 06. [1] (d) The programmer needs to extend the program. The program will use a linear search. (i) The linear search has been written as a pseudocode function that: • takes an array called array of an unknown length as a parameter • takes a search value called value to search for as a parameter • uses a linear search to find the value in the array • returns true if the value is found and false otherwise. Complete the pseudocode function. function linearSearch(array, ) counter = 0 while counter array.length if array[counter] == value then return endif counter = counter endwhile endfunction [5] (ii) One alternative search algorithm is a binary search. Describe the steps in a binary search. [4]