juniorRecursion
How does the Call Stack work with recursion?
Updated Apr 28, 2026
Short answer
Each call pushes a new frame onto the stack; frames are popped as functions return.
Deep explanation
Recursion allows for elegant solutions to hierarchical problems. Each call pushes a new frame onto the stack; frames are popped as functions return. However, it requires careful handling of the stack to prevent memory exhaustion.
Real-world example
Traversing a family tree.
Common mistakes
- Forgetting the base case, leading to infinite recursion.
Follow-up questions
- What is the space complexity?