Practice question · True or false
A recursive function that has a base case cannot recurse forever.
Hints
- Having a base case and reaching it are different things.
- What if each call moves away from the base case?
Show the answer
False
Why
False. The base case must actually be reached: f(n) calling f(n+1), or calling f(n) unchanged, recurses forever with a perfectly good base case sitting there. Termination needs a measure that strictly decreases toward the base on every call, which is the same argument as a loop variant.
Practise Recursion and Iterative Alternatives
The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Recursion and Iterative Alternatives
- The lesson's factorial function is called as factorial(3). Order the events by when they happen in time.
- Every recursive function can be rewritten as a loop, and every loop can be rewritten recursively. Why does…
- A recursive function that would need a million frames crashes in Python and runs fine in a language with…
- Select every statement the lesson supports about choosing recursion over iteration.