Question 7

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

On the specification

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

7 A program uses the recursive function calculate(). The function is written in pseudocode. 1. function calculate(number : byVal) 2. if number == 1 then 3. return number 4. else 5. return number + calculate (number - 1) 6. endif 7. endfunction (a) (i) Give the line number in the algorithm calculate() where a recursive call is made. [1] (ii) State two features of any recursive algorithm. Feature 1 Feature 2 [2] (b) Trace the recursive function calculate() and give the final return value, when the following function call is run: calculate(5) You may choose to use the table below to give your answer. Function call number return calculate(5) [5] (c) Give the pseudocode function call that would return 55 from the recursive function calculate(). [1]