Suppose the stack capacity is 4, and we are performing operations of PUSH, PUSH, PUSH, PUSH and POP, what will happen to the stack after these operations?
Suppose the stack capacity is 4, and we are performing operations of PUSH, PUSH, PUSH, PUSH and POP, what will happen to the stack after these operations?
Solution
✅ Correct Option: 4
Four PUSH operations fill a stack of capacity 4 exactly, so no overflow occurs. The POP then removes the top element, leaving 3 elements.
Option 2: overflow happens only when a PUSH is attempted on an already full stack, which would be a fifth PUSH here.
Option 1: underflow happens only when a POP is attempted on an empty stack.
Option 3: the stack has 4 elements only before the POP.
Related questions:
2026: 26 May Shift 1
2025: 15 May Shift 2
2025: 22 May Shift 1