Question 1

OCR Computer Science June 2022 Algorithms and programming (H446-02)A level21 marks

On the specification

(a)(i)
2.3 Algorithms
(a)(ii)
2.3 Algorithms
(b)(i)
2.2 Problem solving and programming
(b)(ii)
2.2 Problem solving and programming
(b)(iii)
2.2 Problem solving and programming
(c)
2.2 Problem solving and programming
(d)
2.2 Problem solving and programming
(e)
2.1 Elements of computational thinking2.2 Problem solving and programming
Question text

1 A computer program stores data in an array named words. (a) The data in the array needs to be searched for a value that the user inputs. (i) One example of a searching algorithm is a binary search. Identify the precondition for a binary search. [1] (ii) A second example of a searching algorithm is a linear search. Describe how a linear search works. [4] (b) The array words is defined as a global variable and contains these values: "house" "boat" "car" "telephone" "garden" "spice" "elephant" The pseudocode function useWords() here uses the global array words. The number of words in the array words is passed as a parameter. function useWords(numberOfWords : byVal) contents = "" for count = 0 to numberOfWords - 1 contents = contents + words[count] + " " next count return contents endfunction (i) Identify two variables in the function useWords(). 1 2 [2] (ii) numberOfWords is a parameter passed by value. Describe the difference between passing a parameter by value and by reference. [2] (iii) Rewrite the function useWords() to use a while loop instead of a for loop. The function header and close have been written for you. Write your answer using pseudocode or program code. function useWords(numberOfWords : byVal) endfunction [4] (c) Give one benefit and one drawback of declaring the array as a global variable instead of a local variable. Benefit Drawback [2] (d) Describe one feature of an Integrated Development Environment (IDE) that can be used to help write the program and one feature that can be used to help test the program. Write Test [4] (e) Functions and procedures are reusable components. Give two benefits of writing a program with reusable components. 1 2 [2]