Question 4
OCR Computer Science June 2018 Paper 2A level19 marks
On the specification
- (a)
- 2.2 Problem solving and programming
- (b)
- 2.2 Problem solving and programming
- (c)
- 2.2 Problem solving and programming
- (d)
- 2.2 Problem solving and programming
Question text
4 A recursive function, generate, is shown. function generate(num1:byval) if num1 > 10 then return 10 else return num1 + (generate(num1 + 1) DIV 2) endif endfunction (a) Trace the algorithm to show the value returned when generate(7) is called. Show each step of your working. [6] (b) The parameter, num1, is passed by value. Explain why the parameter was passed by value instead of by reference. [2] (c)* Parameters can be used to reduce the use of global variables. Compare the use of parameters to global variables in recursive functions. [9] (d) A student called Jason writes a recursive algorithm. The recursive algorithm uses more memory than if Jason had written it as an iterative algorithm. Explain why the recursive algorithm uses more memory than the iterative algorithm. [2]