Question 3

OCR Computer Science June 2019 Paper 2A level17 marks

On the specification

(a)(i)
2.2 Problem solving and programming
(a)(ii)
2.2 Problem solving and programming
(a)(iii)
2.2 Problem solving and programming
(a)(iv)
2.2 Problem solving and programming
(a)(v)
2.2 Problem solving and programming
(b)
2.2 Problem solving and programming
(c)(i)
2.2 Problem solving and programming
(c)(ii)
2.2 Problem solving and programming
Question text

3 A recursive function, GCD, is given in pseudocode. function GCD(num1, num2) if num2 == 0 then return num1 else return GCD(num2, num1 MOD num2) endif endfunction (a) The function uses branching. (i) Identify the type of branching statement used in the function. [1] (ii) Explain the difference between branching and iteration. [2] (iii) Identify the two parameters in the function. 1 2 [1] (iv) State whether the parameters should be passed by value, or by reference. Justify your answer. [2] (v) Describe the arithmetic operation of MOD. Use an example in your answer. [2] (b) Trace the recursive function when it is called by the statement GCD(250, 20). Give the final value returned. Final return value: [3] (c) The function has been rewritten using iteration instead of recursion. (i) State one benefit and one drawback of using iteration instead of recursion. Benefit Drawback [2] (ii) Complete the missing statements in this iterative version of the function. function newGCD(num1, num2) temp = 0 while (num2 != ) = num2 num2 = num1 MOD num1 = temp endwhile return endfunction [4]