Recursion solves a problem by calling the same function on a smaller copy of it — until a trivial case returns.
1 Base case
The input where the function stops recursing and just returns — the exit door.
2 Recursive case
The function calls itself with a smaller input, trusting the smaller answer.
3 The call stack
Every pending call parks a frame on the stack — factorial(3) stacks three frames.
4 Unwinding
The base case returns first; answers combine as the frames pop.
5 No base case?
Frames pile up forever — the crash is called a stack overflow.
Solve big by thinking small
Base case1The input where the function stops recursing and just returns — the exit door. Recursive case2The function calls itself with a smaller input, trusting the smaller answer. The call stack3Every pending call parks a frame on the stack — factorial(3) stacks three frames. Unwinding4The base case returns first; answers combine as the frames pop. No base case?5Frames pile up forever — the crash is called a stack overflow. 5 building blocks make up Solve big by thinking small
Every recursive call asks the same question: is this small enough to answer directly?
process decision input / output start / end Two tabs, same answer: the recursive version stacks frames, the loop version just multiplies.
preprocessThe preprocessor pastes in iostream for cout.
Memory
no variables yet — press play
Console
output appears as the program runs…
A recursive sum — how deep does it go, and what comes back?
Your predicted output — one line per console line
Hint: sum(4) = 4 + sum(3), sum(3) = 3 + sum(2)... down to sum(0) = 0. Add the pieces back up: 4 + 3 + 2 + 1 + 0.
Click a term, then click its description to lock the pair.
4 conceptsTap a card to expand ?base casedrops into place
?recursive casedrops into place
?call stackdrops into place
?stack overflowdrops into place
01Recursion = a function calling itself with a smaller input.
02Every recursion needs a base case — the stop that makes unwinding possible.
03Each call waits on the stack until the deeper call returns.
04Any loop can be rewritten as recursion and vice versa — pick the clearer one.