juniorStacks
What is Stack Underflow and Overflow?
Updated Apr 28, 2026
Short answer
Overflow happens when pushing to a full stack; Underflow happens when popping from an empty stack.
Deep explanation
Stacks are fundamental in computer science for managing nested or ordered data. Overflow happens when pushing to a full stack; Underflow happens when popping from an empty stack. They ensure that the last item processed is the first one returned, maintaining a strict temporal order.
Real-world example
Back button functionality in a web browser.
Common mistakes
- Forgetting to check for emptiness before popping, causing a runtime error.
Follow-up questions
- What is the space complexity?