Computer Science
Identify the base case(s) in the following recursive function:
def function1(n):
if n == 0:
return 5
elif n == 1:
return 8
elif n > 8 :
return function1(n-1) + function1(n-2)
else:
return -1
Python Functions
2 Likes
Answer
The base case(s) in the given recursive function function1
are:
if n == 0:
- This is the first base case, which returns a specific value (5) when n is equal to 0.elif n == 1:
- This is the second base case, which returns another specific value (8) when n is equal to 1.
These base cases provide termination conditions for the recursive function, ensuring that it stops calling itself when n
reaches 0 or 1.
Answered By
2 Likes