AlgoScope

Base Case and Recursive Case

AnalysisbeginnerRecursion

The recursive case shrinks the problem and the base case stops it; without a base case the stack overflows.

Decision · step 3 of 10The Call Stack: No base case, stack overflow
countDown(3)countDown(2)bottomtoprunning

countDown(2) prints 2 and calls countDown(1). Depth 2.

Open in the player →or start at step 3

What you will see

Frames pile up until the base case; remove the base case and watch the stack overflow.

How the call stack works →

Cost

SpaceO(depth)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input.

Screen readers: Each frame announces its function, arguments and depth; each step announces a call or a return with its value.

Reduced motion: Frames appear and disappear with crossfades instead of sliding.

Before this

Related

Taught by the same lesson

The Call Stack covers these too, in the same run.