For example
def factorial(number):
return number * factorial (number - 1)
Here, there is no condition to end the recursive call. Hence, the function will run infinitely until the its terminated.
This could be extremely dangerous as a non-terminating recursive program can lead to system crash.
Hence, a base case plays an extremely important role for recursive algorithms.
An example of a recursive function with a base condition:
def factorial(number):
if number in (0, 1):
return 1
else:
return number * factorial(number - 1)
Here, the function will stop its recursive call when the base condition is reached, hence terminating itself.