Question:

What will be the sequence of elements removed from the stack after performing the following operations?
Operations:
PUSH(10)
PUSH(20)
POP()
POP()
PUSH(30)
PUSH(40)
POP()
POP()
Options:
(A) 10
(B) 20
(C) 30
(D) 40
Choose the correct sequence from the options given below:

Updated On: May 28, 2025
  • (A), (B), (C), (D)
  • (A), (B), (D), (C)
  • (B), (A), (D), (C)
  • (B), (A), (C), (D)
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Approach Solution - 1

The stack follows Last In, First Out (LIFO) principle, meaning the last element added to the stack will be the first to be removed. Let's analyze the given sequence of operations:

1. PUSH(10): Stack now contains [10]
2. PUSH(20): Stack now contains [10, 20]
3. POP(): Removes 20; stack now contains [10]
4. POP(): Removes 10; stack is now empty []
5. PUSH(30): Stack now contains [30]
6. PUSH(40): Stack now contains [30, 40]
7. POP(): Removes 40; stack now contains [30]
8. POP(): Removes 30; stack is now empty []

The sequence of elements removed from the stack is 20, 10, 40, 30. Based on the given options, the correct sequence is (B), (A), (D), (C).
Was this answer helpful?
0
0
Hide Solution
collegedunia
Verified By Collegedunia

Approach Solution -2

The sequence of elements removed from the stack is 20, 10, 40, 30.

Additional Context:

  • Stack Operations Breakdown:
    1. PUSH(10) → Stack: [10]
    2. PUSH(20) → Stack: [10, 20]
    3. POP() → Removes 20 (B) → Stack: [10]
    4. POP() → Removes 10 (A) → Stack: []
    5. PUSH(30) → Stack: [30]
    6. PUSH(40) → Stack: [30, 40]
    7. POP() → Removes 40 (D) → Stack: [30]
    8. POP() → Removes 30 (C) → Stack: []
  • LIFO Principle:
    • Last element pushed is first popped
    • Visualized as vertical stack (like plates)
  • Resulting Sequence:
    • First POP pair: 20, 10
    • Second POP pair: 40, 30

Correct Answer: (3) (B), (A), (D), (C).

Was this answer helpful?
0
0