This is the reduced time complexity version Fibonacci Series. In this program, the caching feature reduces the normal way of calculating Fibonacci series from O(2^n) to O(n) by eliminating the repeats in the recursive tree of Fibonacci series Originally implemented by Akash Rana. Source : http://stackoverflow.com/a/26118289/3676464
import sys table = [0]*1000 def FastFib(n): if n<=1: return n else: if(table[n-1]==0): table[n-1] = FastFib(n-1) if(table[n-2]==0): table[n-2] = FastFib(n-2) table[n] = table[n-1] + table[n-2] return table[n] print(FastFib(10))
55
Comments :