KnowledgeBoat Logo

Computer Science

Is it necessary to have a base case in a recursive function? Why/Why not?

Python Functions

1 Like

Answer

Yes, it is necessary to have a base case in a recursive function. Without a base case, the recursive function would continue calling itself indefinitely, leading to infinite recursion. This can cause the program to run out of memory and crash, resulting in an error. The base case provides a condition that stops the recursion, allowing the function to return a result and terminate.

Answered By

3 Likes


Related Questions