Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

fibonacci series using dynamic programmig approach

def fib(n, solved):
 
    # Base case
    if n == 0 or n == 1 :
        solved[n] = n
 
    # If the value is not calculated yet then calculate it
    if solved[n] is None:
        solved[n] = fib(n-1, solved)+fib(n-2, solved)
 
    # return the value from table for n
    return solved[n]

n = 12
solved = [None]*(n+1)
fib(n, solved)
for i, num in enumerate(solved):
	print(i, num)
Source by codefinity.com #
 
PREVIOUS NEXT
Tagged: #fibonacci #series #dynamic #programmig #approach
ADD COMMENT
Topic
Name
4+9 =