top of page

PROGRAMMING CHALLENGES

Recursive Fibonacci to Iterative

Difficulty:

2 Medium

2.5 Recursion

Topic:

The following pseudocode generates the nth Fibonacci number using recursion. Rewrite it using an iterative approach instead.

Fibonacci sequences are typically defined with a base case and a recursive case. Iteration can achieve the same with loops and variables to hold the sequence values.

FUNCTION fibonacci(n) IF n <= 1 RETURN n ELSE RETURN fibonacci(n - 1) + fibonacci(n - 2) ENDFUNCTION

Need help with your programming skills?

If you need more help than just independent practise, then we're here for you. Book a 1:1 with us and we will be able to guide you to becoming a proficient programmer who can tackle any of the challenges an exam board can throw at you.

bottom of page