Consider the following operations performed on a stack of size 5 : Push (a);…
2016
Consider the following operations performed on a stack of size 5 :
Push (a); Pop() ; Push(b); Push(c); Pop();
Push(d); Pop();Pop(); Push (e)
Which of the following statements is correct ?
- A.
Underflow occurs
- B.
Stack operations are performed smoothly
- C.
Overflow occurs
- D.
None of the above
Attempted by 1080 students.
Show answer & explanation
Correct answer: B
Simulate the operations (top shown on the right):
Push(a) => [a]
Pop() => []
Push(b) => [b]
Push(c) => [b, c]
Pop() => [b]
Push(d) => [b, d]
Pop() => [b]
Pop() => []
Push(e) => [e]
Key checks:
No underflow: every Pop() removed an element that existed at that time; no Pop() was called on an empty stack.
No overflow: the stack capacity is 5 and the maximum number of elements present at once was 2, so no Push() exceeded capacity.
Conclusion:
All operations are performed smoothly. The final stack contains e (with e at the top).