Question 2
OCR Computer Science Specimen Paper 2A level25 marks
On the specification
- (a)
- 2.3 Algorithms
- (b)
- 2.3 Algorithms
- (c)
- 2.2 Problem solving and programming
- (d)(i)
- 2.2 Problem solving and programming
- (d)(ii)
- 2.2 Problem solving and programming
- (e)
- 2.2 Problem solving and programming
- (f)
- 2.2 Problem solving and programming2.3 Algorithms
Question text
2 Consider the following algorithm in Fig.2, expressed in pseudocode, as a function S: function S(A[0..N-1], value, low, high) if (high < low)then return error_message endif mid = (low + high) / 2 if (A[mid] > value)then return S(A, value, low, mid-1) elseif (A[mid] < value)then return S(A, value, mid+1, high) else return mid endif endfunction Fig.2 (a) State the name of the algorithm implemented in Fig.2. [1] (b) Describe the purpose of this algorithm. [2] (c) Parameters are passed to this function. Complete the following table to identify these parameters and the purpose of each. Parameter name Purpose [8] (d) (i) Describe what is meant by recursion. [2] (ii) Identify one example of where recursion occurs in this algorithm. [1] (e) Explain how the algorithm in Fig.2 is an example of a divide and conquer approach. [3] (f) Rewrite the algorithm in Fig.2 without using recursion. Annotate your pseudocode with comments to show how it solves the problem.