Question:

Consider an empty stack. What will the stack look like (starting from the top) after executing the following operations in sequence?
1. push(7)
2. push(5)
3. push(9)
4. push(11)
5. pop()
6. push(22)
(A) 22
(B) 9
(C) 5
(D) 7
Choose the correct answer from the options given below:

Show Hint

Always pay close attention to the requested readout direction: "starting from the top" means you read the most recently pushed surviving element first.
Updated On: Sep 7, 2026
  • (A), (B), (C), (D)
  • (D), (C), (B), (A)
  • (B), (A), (D), (C)
  • (C), (B), (D), (A)
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

Concept:
A stack functions on the Last-In-First-Out (LIFO) order.
Pushing places an element on the top, while popping removes the element currently at the top.

Step 1: Tracing the Stack Operations Step-by-Step:

Let the stack contents be represented from bottom to top as a list:
1. Initial state: Stack = $[\,]$
2. push(7): Stack = $[7]$
3. push(5): Stack = $[7, 5]$
4. push(9): Stack = $[7, 5, 9]$
5. push(11): Stack = $[7, 5, 9, 11]$ (Top is 11)
6. pop(): Removes the topmost element, which is 11. Stack becomes $[7, 5, 9]$
7. push(22): Stack = $[7, 5, 9, 22]$

Step 2: Reading from the Top of the Stack:

Reading the stack elements from the top down to the bottom yields:
- Top: 22 $\rightarrow$ corresponds to (A)
- Next: 9 $\rightarrow$ corresponds to (B)
- Next: 5 $\rightarrow$ corresponds to (C)
- Bottom: 7 $\rightarrow$ corresponds to (D)
The resulting sequence from top to bottom is (A), (B), (C), (D).
Final Answer:
The stack from top to bottom is (A), (B), (C), (D), which is option (A).
Was this answer helpful?
0
0