+ 1
How can I know the base case of a recursive function please???
The base case as a condition to avoid infinite loop
3 Respuestas
+ 2
You could think about this like:
You are writing a recursive function, for example to add all positive numbers up to n.
When you call this function initially you will pass the value of n as parameter.
You could say the base case is the value that will run every time, no matter how you choose the value of n. So in this example the base case is 1 because it is the smallest positive number. Any n parameter must be 1 or larger, and you decrement it by each recursive call.
+ 5
It depends on the problem. It is obvious in most cases, and sometimes they mention it. Can you share the problem?
0
A case that doesen't involve any further calls to that function