Call Stack
The runtime stack of function frames, pushed on every call and popped on every return. The reason recursion works and overflows.
The Call Stack: fact(5) down and back up
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
Related
Leads to
Topics that need this one first.
Taught by the same lesson
The Call Stack covers these too, in the same run.