# Program 1
fibSeries = {}
def fib(n):
a,b = 1,1
for i in range(1,n+1):
if i <= 2:
f = 1
else:
f = a + b
a = b
b = f
fibSeries[i] = f
return f
print (fib(number))
print (fibSeries)
# Program 2
fibSeries={}
def fib(n):
for k in range(1,n+1):
if k <= 2: f = 1
else: f = fib(k-1) + fib(k-2)
fibSeries[k] = f
return f
print(fib(number))
print(fibSeries)
I have started dynamic programming and my first program is to find Fibonacci series. I have written the above two programs. My first question is which among these programs comes under dynamic programming? Which among these two programs is a better one? Is there a better way than program 1 to find the nth Fibonacci number faster? Is program 2 better than recursion? And how to find the number of times the function is called in program 2?