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

How can I run a C++ program directly from Windows?

How-can-I-run-a-C-program-directly-from-Windows