Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

Fibonacci

Three implementations with a timing comparison demonstrating the practical impact of algorithm choice. See Fibonacci sequence — Wikipedia.

Implementations

Function Approach Time complexity Space complexity
fib(n) Naive recursion O(2ⁿ) O(n) call stack
fib_iterative(n) Iterative O(n) O(1)
fib_memo(n) Memoized recursion O(n) O(n)

Key concept: Memoization

Memoization stores the result of each function call so it is never computed twice. The memoized version has the simplicity of recursion but the efficiency of iteration.

Run

python fibonacci.py

Prints the first 10 values then a timing table for n = 1 to 35.