saving . . . saved Recursion has been deleted. Recursion has been hidden .
Recursion
Title
Question
What do we mean by depth of recursion & how can we count the depth of each recursion?

Python General None min None sec 29-07-19, 2:29 p.m. JassiAnand

Answers:

Depth of recursion: Number of times a function is called recursively. 

Example: Consider a program to compute the factorial of a number using a recursion. When given a large input, the program crashed and gives a "maximum recursion of depth exceeded error".

# A simple recursive function 
# to compute the factorial of a number 
def fact(n): 
  
    if(n == 0): 
        return 1
  
    return n * fact(n - 1) 
  
  
if __name__ == '__main__': 
  
    # taking input 
    f = int(input('Enter the number: \n')) 
  
    print(fact(f))

 You can check the recursion limit with sys.getrecursionlimitand change the recursion limit with sys.setrecursionlimitbut doing so is dangerous. The standard limit is a little conservative, but Python stackframes can be quite big.
18-04-20, 12:34 a.m. iakashchavan


Log-in to answer to this question.