Mathematics I / Recursion
Practice question · Multiple choice

A recursive function calls itself, which sounds like it should never finish. Why does a correct recursion terminate, and what happens when the base case is missing?

Hints
  1. For factorial(n) calling factorial(n−1), what happens to the argument at each step?
  2. Ask what stops the descent.
Show the answer

A. Because each call takes a strictly smaller input toward a base case.

Why

Two conditions must hold: the argument strictly decreases toward the base, and the base handles the smallest input without recursing. Remove it and the descent runs past zero, adding frames until the stack is exhausted. The parallel with induction is exact, base case, inductive hypothesis, and proving a recursion correct is an induction proof.

Read the lesson: Recursion →

Practise Recursion

The app has 6 more questions on this lesson, and keeps your place in the course. Mathematics I is free to start.

More questions on Recursion