Consider the following stack operations: push(10), push(20), pop(), push(30), pop(). What is the sequence of elements removed from the stack?
Options
- A. 10, 20
- B. 20, 30
- C. 30, 20
- D. More than one of the above
- E. None of the above
Quiz Practice:
B. 20, 30
A stack follows LIFO, meaning the last element inserted is the first element removed. First, 10 and 20 are pushed, so 20 is on top. The first pop removes 20. Then 30 is pushed and becomes the top element. The second pop therefore removes 30. Hence the removal sequence is 20, 30. Such operation-tracing questions are common in DSA examinations.