Computer Science
What happens if the base condition isn't defined in recursive programs?
- Program gets into an infinite loop
- Program runs once
- Program runs n number of times, where n is the argument given to the function
- An exception is thrown
Python Functions
1 Like
Answer
Program gets into an infinite loop
Reason — When the base condition in a recursive program is not properly defined, the recursive calls continue indefinitely without a stopping criterion. This leads to an infinite loop where the program keeps executing recursive calls without making progress towards a termination point.
Answered By
3 Likes
Related Questions
Which of the following statements is false about recursion?
- Every recursive function must have a base case.
- Infinite recursion can occur if the base case isn't properly mentioned.
- A recursive function makes the code easier to understand.
- Every recursive function must have a return value.
What is the output of the following snippet?
def fun(n): if (n > 100): return n - 5 return fun (fun (n+11) ) print(fun(45))
- 50
- 100
- 74
- Infinite loop
Assertion (A): Function can take input values as parameters, execute them and return output (if required) to the calling function with a return statement.
Reasoning (R): A function in Python can return multiple values.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Assertion (A): If the arguments in a function call statement match the number and order of arguments as defined in the function definition, such arguments are called positional arguments.
Reasoning (R): During a function call, the argument list first contains default argument(s) followed by positional argument(s).
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.