Sunday, June 28, 2020

Limits of recursive functions

The biggest drawback of recursive functions is that it has a limit to the maximum number of recursive calls it can have( also called the maximum possible depth of recursion).


This is best explained by a simple recursive function shown below which prints the sum of two numbers.


As you can see, we cannot add a number greater than 994 to 5 using recursion because in doing so the maximum recursion depth, which is only 1000 in case of Python gets exceeded. 

The number of recursions( iterations) cannot be greater than 1000 in Python.

No comments:

Post a Comment

इश्क में ग़ैरत-ए-जज़्बात ने रोने ना दिया - सुदर्शन फ़ाकिर

 इश्क में ग़ैरत-ए-जज़्बात ने रोने ना दिया वरना क्या बात थी किस बात ने रोने ना दिया आप कहते थे कि रोने से ना बदलेंगे नसीब उमर भर आप की इस बात...