AlgoFrames

Factorial trace

Warm-up · Predict the result · about 3 min

This version of fact prints each result just before it returns. What does fact(4) print? Write the numbers in order, separated by spaces.

Example 1

Input:

2

Output:

2

fact(1) returns without printing; fact(2) prints 2.

Constraints

  • Answer with the printed numbers in order.

Learn the idea first: Recursion: base case, recursive case, the call stack, a visual lesson.

More Recursion: base case, recursive case, the call stack problems