Recursion and the call stack

A function calling itself is just the call stack doing its job. Watch the frames pile up and unwind.

Recursion is a function calling itself with a smaller problem. Each call pushes a new frame onto the call stack, holding its own arguments, until the base case says stop.

Then the magic half: the stack unwinds. Each frame pops and hands its result to the caller below it. Forget the base case and the frames never stop piling up: that's literally a stack overflow.

Remember this

  • Every recursive call is a new stack frame
  • The base case stops the descent
  • Results assemble as the stack unwinds

Got a different question? SeaThru generates a fresh video for any topic where systems talk or data structures move.

Ask your own question →

Keep learning