Mathematics I / Recursion
Practice question · Numerical answer

Computing fact(4) recursively, how many calls to fact are made in total, counting the original call and the base-case call?

Hints
  1. List the arguments of every call that occurs.
  2. The chain runs 4, 3, 2, 1, 0.
Show the answer

5

Why

The calls are fact(4), fact(3), fact(2), fact(1), fact(0), five in all. Each is a pending frame on the call stack, which is why a recursion that never reaches its base case exhausts memory rather than merely looping.

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