ITPEC FE Subject B April 2024 Question 7

Source exam: ITPEC FE Subject B April 2024Topic: Math & Numbers

ITPEC FE Subject B April 2024 — Question 7 of 20

Fibonacci sequence implemented via recursion with base cases and recursive call.

The sequence starts at position 1: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34.

Base cases: fibo(1) = 0 and fibo(2) = 1. Since the function returns n - 1 in the base branch, both n = 1 (returns 0) and n = 2 (returns 1) must be caught by condition A:

A = (n = 1) or (n = 2)

Recursive case: every other value is the sum of the two preceding values:

B = fibo(n-1) + fibo(n-2)

Verification: fibo(9) = fibo(8) + fibo(7) = 13 + 8 = 21

Why not others:
- (a), (b), (c) — condition n = 1 misses n = 2, so fibo(2) would recurse into fibo(1) + fibo(0), and fibo(0) has no base case → infinite recursion

- (d), (e), (f) — condition n > 1 puts recursion in the if branch and the base case in else, which is inverted logic; only n = 1 returns a base value, missing n = 2

- (g) — correct condition but fibo(n-1) + 1 is not Fibonacci addition

- (h) — correct condition but fibo(n-1) + n adds the position instead of the previous term

Key rule: Fibonacci recursion needs two base cases (n = 1 and n = 2) because the recursive formula references two prior positions.

AI-generated — may contain errors

The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.