AlgoScope

Call Stack

The runtime stack of function frames, pushed on every call and popped on every return. The reason recursion works and overflows.

Data structures, data structure, beginner
Call fact(5), depth 1.fact(5)bottomtoprunning
Call fact(5), depth 1.fact(5)bottomtoprunning

The Call Stack: fact(5) down and back up

Decision, step 2 of 14

fact(5) needs fact(4) before it can multiply, so it calls it. The new frame goes on top and fact(5) waits below it.

Cost

Push frame
O(1)
Pop frame
O(1)
Space
O(depth)

Before this

Leads to

Topics that need this one first.

Taught by the same lesson

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