Question bank › A-level Computer Science › Fundamentals of programming

Subroutines, parameters, stack frames and recursion

Answer on paper first, then reveal the mark scheme one mark at a time.

1Standard5 marks

The recursive function F is shown below.

FUNCTION F(a, b)
   IF b = 0 THEN
      RETURN a
   ELSE
      RETURN F(b, a MOD b)
   ENDIF
ENDFUNCTION

(a) State the value returned by the call F(84, 36). [1]

(b) State how many times F is called in total, including the original call, when F(84, 36) is executed. [1]

(c) State what the function F calculates. [1]

(d) Identify the base case in F and explain why a recursive subroutine must have a base case. [2]

2Hard4 marks

Consider the Python program below.

def change(x, items):
    x = x + 1
    items.append(x)

a = 5
b = [1]
change(a, b)
print(a, b)

(a) State the output of the program. [2]

(b) Explain why the value of a and the contents of b are affected differently by the call to change. [2]

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session