ac812 / mcb-python

Master repository for MCB
https://ac812.github.io/mcb-python/
1 stars 0 forks source link

Fibonacci recursion #8

Open ac812 opened 1 year ago

ac812 commented 1 year ago

re write exercise Fibonacci recursion in Practical 4 so that it only returns the ith Element of the Sequence not the full sequence - O2 complexity

ac812 commented 1 year ago

possible other option: def fibonacci(n): if n==0: return 0 if n==1: return [1] if n == 2: return [1,1] else: prev = fibonacci (n-1) return prev + [prev[-1]+prev[-2]]