Mathematics I / Recursion
Practice question · Put in order

Order what happens when a recursive factorial computes 3 factorial.

Hints
  1. Recursion descends to the base case before anything is actually multiplied.
  2. Nothing can be returned until the base case is reached.
Show the answer
  1. The call for 3 needs the value for 2
  2. The call for 2 needs the value for 1
  3. The call for 1 needs the value for 0
  4. The base case gives the value for 0 as 1
  5. The results multiply back up to give 6
Why

The calls stack downward to the base case, which is the first value actually known, and only then does the multiplication unwind upward. Without the base case the descent never stops, the stack overflow.

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