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

Sacred Thought

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...