AlgoScope

Recursion to Iteration

AnalysisintermediateRecursion

A tail call is a loop in disguise: replace the call with an update of the arguments and jump back.

Decision · step 2 of 8The Call Stack: Tail recursion reuses the frame
factTail(4, 5)bottomtop

factTail(5, 1) calls factTail(4, 1 x 5 = 5) and has nothing to do with the result but pass it on. The frame is reused: same slot, new arguments.

Open in the player →or start at step 2

What you will see

The same algorithm with the call stack and with an explicit stack, moving in lockstep.

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.

Taught by the same lesson

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