What is the maximum recursion depth in Python, and how to increase it?

前端 未结 17 2892
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 04:14

I have this tail recursive function here:

def recursive_function(n, sum):
    if n < 1:
        return sum
    else:
        return recursive_function(n-1         


        
17条回答
  •  南旧
    南旧 (楼主)
    2020-11-21 05:07

    We could also use a variation of dynamic programming bottom up approach

    def fib_bottom_up(n):
    
        bottom_up = [None] * (n+1)
        bottom_up[0] = 1
        bottom_up[1] = 1
    
        for i in range(2, n+1):
            bottom_up[i] = bottom_up[i-1] + bottom_up[i-2]
    
        return bottom_up[n]
    
    print(fib_bottom_up(20000))
    

提交回复
热议问题