STACKS MCQs For Data Structures
Q1.
Which of the following operations results in stack underflow?
A) Pushing an element into the stack
B) Popping an element from an empty stack
C) Peeking at the top element
D) Checking if stack is full
Answer: B
Explanation:
Stack underflow occurs when we attempt to remove (pop) an element from an empty stack. It’s a run-time error similar to accessing invalid memory.
Q2.
If elements 10, 20, 30, 40 are pushed in that order into a stack and one pop operation is performed, then which element will be on the top?
A) 20
B) 30
C) 40
D) 10
Answer: B
Explanation:
After push sequence: [10, 20, 30, 40]
Pop → removes 40 → top becomes 30.
Q3.
In a stack, if the sequence of operations is:
Push(1), Push(2), Pop(), Push(3), Pop(), Pop()
The sequence of popped elements is:
A) 1, 2, 3
B) 2, 3, 1
C) 2, 3, —
D) 2, 3, 1
Answer: C
Explanation:
Operations:
Push(1) → [1]
Push(2) → [1, 2]
Pop() → removes 2
Push(3) → [1, 3]
Pop() → removes 3
Pop() → removes 1
Hence sequence = 2, 3, 1.
Q4.
The postfix expression for the infix (A + B) * (C - D) is:
A) A B + C D - *
B) A B C D + - *
C) A B + * C D -
D) A B C D - + *
Answer: A
Explanation:
Using stack for conversion:
Infix → Postfix = A B + C D - *
Q5.
What will be the output of the following postfix expression evaluation?6 3 2 + * 4 /
A) 7.5
B) 9.0
C) 4.5
D) 12.0
Answer: A
Explanation:
Postfix evaluation using stack:
→ 3 2 + = 5
→ 6 * 5 = 30
→ 30 / 4 = 7.5
Q6.
Which data structure is most suitable for function call management?
A) Queue
B) Array
C) Stack
D) Linked List
Answer: C
Explanation:
Stacks manage function calls using LIFO — the most recently called function is completed first.
Q7.
What is the time complexity of Push and Pop operations in a stack implemented using a linked list?
A) O(1)
B) O(log n)
C) O(n)
D) O(n log n)
Answer: A
Explanation:
Both Push and Pop are done at the top of the stack → constant time.
Q8.
Which of the following is not an application of a stack?
A) Expression evaluation
B) Backtracking algorithms
C) Level order traversal
D) Syntax parsing
Answer: C
Explanation:
Level order traversal uses a queue, not a stack.
Q9.
If the stack size is 3 and the input sequence is A, B, C, D, which of the following pop sequences is not possible?
A) C, B, A, D
B) B, C, D, A
C) C, D, B, A
D) A, B, C, D
Answer: B
Explanation:
Stack cannot produce B, C, D, A because D cannot be popped before A without being pushed after it.
Q10.
In a stack implemented using an array of size N, the top index starts at?
A) 0
B) 1
C) -1
D) N
Answer: C
Explanation:
Initially, the stack is empty, so top = -1. After first push, top = 0.
Q11.
If an infix expression is A + B * C - D / E, what is its postfix form?
A) A B C * + D E / -
B) A B + C D * / E -
C) A B + C * D / E -
D) A B C + * D / E -
Answer: A
Explanation:
Follow precedence: * and / before + and -.
Hence postfix → A B C * + D E / -.
Q12.
A stack contains elements [5, 10, 15, 20] (top = 20). After performing Pop(), Push(25), Pop(), Push(30), the top element will be:
A) 10
B) 15
C) 25
D) 30
Answer: D
Explanation:
Pop() → remove 20
Push(25) → [5,10,15,25]
Pop() → remove 25
Push(30) → [5,10,15,30]
Top = 30.
Q13.
Which of the following can be efficiently implemented using two stacks?
A) Queue
B) Linked List
C) Priority Queue
D) Binary Search Tree
Answer: A
Explanation:
A queue can be implemented using two stacks — one for enqueue, one for dequeue.
Q14.
What happens when you attempt to push an element into a full stack?
A) Overflow
B) Underflow
C) Both
D) Nothing
Answer: A
Explanation:
Pushing into a full stack causes stack overflow error.
Q15.
Which of the following postfix expressions corresponds to the infix (A + B) * (C + D)?
A) A B + C D + *
B) A B C + D + *
C) A B * C D + +
D) A B + * C D +
Answer: A
Explanation:
Both (A + B) and (C + D) are evaluated first, so postfix = A B + C D + *.
Q16.
If stack operations are limited to a maximum depth of 5, how many elements can be pushed before overflow occurs?
A) 4
B) 5
C) 6
D) 0
Answer: B
Explanation:
Maximum stack size = 5 elements. Overflow occurs after pushing the 6th element.
Q17.
Which of the following statements about stacks is incorrect?
A) Stack can be implemented using linked list
B) Stack is a FIFO structure
C) Stack supports recursion
D) Stack supports LIFO order
Answer: B
Explanation:
Stack follows LIFO, not FIFO. Hence option B is incorrect.
Q18.
If the stack is implemented using an array, what is the condition for overflow?
A) top = size – 1
B) top = -1
C) top = 0
D) top = size
Answer: A
Explanation:
When top reaches size – 1, stack is full → overflow occurs.
Q19.
Which of the following expressions represents a valid postfix form?
A) A B + C *
B) A + B * C
C) A B C +
D) A + + B
Answer: A
Explanation:A B + C * is valid postfix: operands first, operators follow.
Q20.
During recursion, function calls are managed by which structure?
A) Stack
B) Queue
C) Tree
D) Graph
Answer: A
Explanation:
Recursive calls are stored in a call stack; each call waits until the next completes.
Q21.
If a stack is used to reverse a string of length n, the total number of push and pop operations required is:
A) n
B) 2n
C) n + 1
D) n²
Answer: B
Explanation:
Each character is pushed once and popped once → total = 2n operations.
Q22.
Given the infix expression A * (B + C) / D, the postfix form is:
A) A B C + * D /
B) A B + C * D /
C) A * B C + / D
D) A B * C D + /
Answer: A
Explanation:
Using operator precedence and associativity → postfix is A B C + * D /.
Q23.
What is the maximum number of elements that can be present in the stack at any time during the evaluation of postfix expression 5 6 2 + * 12 4 / -?
A) 3
B) 4
C) 5
D) 6
Answer: B
Explanation:
While evaluating postfix, the stack size reaches a maximum of 4 elements before starting to reduce.
Q24.
Stack can be implemented using which of the following?
A) Arrays
B) Linked Lists
C) Both A and B
D) Trees
Answer: C
Explanation:
Stacks can be implemented using either arrays or linked lists.
Q25.
If a stack is used to implement a queue, how many stacks are required?
A) 1
B) 2
C) 3
D) 4
Answer: B
Explanation:
A queue can be implemented using two stacks — one for enqueue and one for dequeue.
Q26.
In the postfix expression 2 3 4 * + 5 -, the result is:
A) 9
B) 10
C) 12
D) 15
Answer: A
Explanation:
Evaluate step-by-step:
3 * 4 = 12 → 2 + 12 = 14 → 14 – 5 = 9.
Q27.
Which of the following can be used to check balanced parentheses?
A) Stack
B) Queue
C) Tree
D) Array
Answer: A
Explanation:
A stack helps match every opening and closing bracket using LIFO order.
Q28.
To convert infix (A + B) * C to prefix form, we get:
A) * + A B C
B) + * A B C
C) A B + C *
D) A + B * C
Answer: A
Explanation:
Prefix form is obtained by reversing infix → prefix: * + A B C.
Q29.
Which of the following best describes a stack overflow condition?
A) Top pointer exceeds the maximum index
B) Top pointer becomes -1
C) Stack becomes empty
D) Stack elements get sorted
Answer: A
Explanation:
Overflow occurs when top exceeds the maximum array index.
Q30.
Which of the following problems can be solved efficiently using stacks?
A) Tower of Hanoi
B) Breadth-First Search
C) Shortest Path
D) Depth-First Search
Answer: D
Explanation:
DFS uses a stack (explicit or implicit recursion).
Q31.
In which order are function calls stored in the call stack?
A) First in, first out
B) Last in, first out
C) Random
D) Sorted order
Answer: B
Explanation:
The most recent function call is completed first (LIFO).
Q32.
Which operation of stack cannot be implemented in O(1) time if stack is implemented using linked list?
A) Push
B) Pop
C) Traversal
D) Peek
Answer: C
Explanation:
Traversal through the entire stack requires O(n) time.
Q33.
The minimum number of stacks required to evaluate a postfix expression is:
A) 1
B) 2
C) 3
D) Depends on expression
Answer: A
Explanation:
Only one stack is sufficient for postfix evaluation.
Q34.
Which of the following statements about stacks is false?
A) Top element can be accessed directly
B) Elements can be inserted at any position
C) Insertion and deletion occur at the same end
D) Stack is a LIFO structure
Answer: B
Explanation:
In a stack, insertion/deletion only occur at the top.
Q35.
What is the result of evaluating 4 5 + 2 * 3 /?
A) 6
B) 3
C) 4
D) 7
Answer: A
Explanation:
(4 + 5) = 9 → 9 * 2 = 18 → 18 / 3 = 6.
Q36.
A stack is said to be empty when:
A) Top = 0
B) Top = -1
C) Top = n
D) Top = n-1
Answer: B
Explanation:
Initially, top = -1 indicates stack is empty.
Q37.
Infix: (A + B) * (C + D) / E → Postfix?
A) A B + C D + * E /
B) A B C D + + * E /
C) A B C D + + / E *
D) A B + * C D + E /
Answer: A
Explanation:
Operator precedence and associativity yield postfix A B + C D + * E /.
Q38.
The main advantage of implementing stack using linked list over array is:
A) Dynamic memory allocation
B) Faster operations
C) Constant space
D) Easier traversal
Answer: A
Explanation:
Linked lists allow dynamic memory allocation, no overflow unless memory full.
Q39.
Stack memory is used for which of the following in C language?
A) Global variables
B) Static variables
C) Function calls and local variables
D) Constants
Answer: C
Explanation:
Each function call and its local variables are stored on stack memory.
Q40.
Which of the following postfix expressions is equivalent to infix (A - B) / (C * D)?
A) A B - C D * /
B) A B C D * / -
C) A B C D / * -
D) A B C * D / -
Answer: A
Explanation:
Postfix: operands followed by operators → A B - C D * /.
Q41.
Which data structure is used by the compiler to implement recursion?
A) Stack
B) Queue
C) Tree
D) Graph
Answer: A
Explanation:
Each recursive call is stored in stack memory until completion.
Q42.
A stack is used to convert a decimal number to binary by:
A) Pushing remainders and popping them in reverse order
B) Direct division
C) Multiplication
D) Recursion only
Answer: A
Explanation:
Remainders are stored in stack to reverse order for correct binary digits.
Q43.
What is the maximum stack depth during evaluation of postfix 5 9 8 + 4 6 * * 7 + *?
A) 3
B) 4
C) 5
D) 6
Answer: C
Explanation:
Maximum of 5 elements temporarily exist on stack before final computation.
Q44.
If stack S1 is used to implement another stack S2, then how many stacks in total are used?
A) 1
B) 2
C) 3
D) 4
Answer: B
Explanation:
One acts as primary, another as helper → total 2.
Q45.
Which is the correct prefix expression for (A + B) * (C - D)?
A) * + A B - C D
B) + A B * - C D
C) * - C D + A B
D) + * A B - C D
Answer: A
Explanation:
Prefix form: operator precedes both operands → * + A B - C D.
Q46.
In expression evaluation using stack, the stack is used to store:
A) Operands only
B) Operators only
C) Both operands and operators
D) Intermediate results
Answer: D
Explanation:
During postfix evaluation, intermediate results are stored on stack.
Q47.
Which of the following statements is true for an empty stack?
A) Push not allowed
B) Pop not allowed
C) Both allowed
D) Peek allowed
Answer: B
Explanation:
Pop operation not allowed on empty stack (causes underflow).
Q48.
Stack can be used to evaluate which of the following directly?
A) Prefix expressions
B) Postfix expressions
C) Infix expressions
D) None
Answer: B
Explanation:
Postfix evaluation is straightforward using a single stack.
Q49.
Which operation of stack requires modification of the top pointer?
A) Push
B) Pop
C) Both A and B
D) None
Answer: C
Explanation:
Both push and pop modify the top pointer accordingly.
Q50.
In stack implementation using arrays, overflow can be handled by:
A) Increasing array size dynamically
B) Stopping insertion
C) Decreasing stack size
D) Deleting elements
Answer: A
Explanation:
Dynamic resizing (e.g., using realloc in C) can handle overflow.
Q51.
What is the minimum number of stacks required to sort a stack using only stack operations?
A) 1
B) 2
C) 3
D) 4
Answer: B
Explanation:
Two stacks are enough — one as temporary buffer.
Q52.
In a postfix expression, if there are n operators, the total number of operands must be:
A) n
B) n + 1
C) 2n
D) n – 1
Answer: B
Explanation:
Valid postfix expression: #operands = #operators + 1.
Q53.
Which of the following is an invalid postfix expression?
A) A B +
B) A B + C
C) A B C + *
D) A B + C *
Answer: B
Explanation:A B + C has one extra operand, so invalid.
Q54.
Which of these is an application of stack in operating systems?
A) CPU scheduling
B) Expression evaluation
C) Memory management
D) Recursive function handling
Answer: D
Explanation:
Stack maintains function call records in memory.
Q55.
Which of the following postfix expression evaluates to 100?
Expression: 5 5 * 4 *
A) 20
B) 100
C) 25
D) 50
Answer: B
Explanation:
55=25, 254=100.
Q56.
If the stack grows downward in memory, what happens to the stack pointer during push?
A) Increments
B) Decrements
C) Remains same
D) Jumps randomly
Answer: B
Explanation:
Stack grows downward → push decreases stack pointer.
Q57.
In a function call stack, return address is stored in:
A) Stack frame
B) Heap
C) Code segment
D) Static area
Answer: A
Explanation:
Each function has its own stack frame containing return address.
Q58.
Stack frame does not contain:
A) Local variables
B) Return address
C) Global variables
D) Saved registers
Answer: C
Explanation:
Global variables are stored in static data segment, not in stack.
Q59.
A stack is said to be full when:
A) top == size
B) top == size – 1
C) top == 0
D) top == -1
Answer: B
Explanation:
Top equal to size–1 indicates full stack in array implementation.
Q60.
If the push sequence is 1,2,3,4 and pop sequence is 4,3,2,1, the structure is definitely a:
A) Queue
B) Stack
C) Heap
D) Tree
Answer: B
Explanation:
This is perfect LIFO order, hence stack.
Q61.
Which of the following postfix expression equals infix (A + B) / (C - D)?
A) A B + C D - /
B) A B C D + / -
C) A B + / C D -
D) A B / + C D -
Answer: A
Explanation:
Postfix of (A + B)/(C - D) = A B + C D - /.
Q62.
Which one of the following stack operations requires overflow checking?
A) Pop
B) Peek
C) Push
D) None
Answer: C
Explanation:
Push may exceed capacity; overflow must be checked.
Q63.
During recursive function calls, each call is stored as:
A) Stack frame
B) Linked node
C) Queue node
D) Array block
Answer: A
Explanation:
Every function invocation gets its own stack frame.
Q64.
Which traversal technique uses stack in tree operations?
A) Level-order
B) Inorder
C) Breadth-first
D) All
Answer: B
Explanation:
Inorder traversal (iterative) uses stack to simulate recursion.
Q65.
Which of the following postfix expressions is equivalent to infix A + B * (C + D)?
A) A B C D + * +
B) A B * C D + +
C) A B C D + + *
D) A + B * C D +
Answer: A
Explanation:
Parenthesis around (C + D) → postfix: A B C D + * +.
Q66.
Stack is most suitable for solving which of the following?
A) Balancing parentheses
B) CPU Scheduling
C) Job Queueing
D) Page Replacement
Answer: A
Explanation:
Stack matches opening and closing symbols efficiently.
Q67.
Which of the following uses stack internally?
A) Recursion
B) Iteration
C) Binary Search
D) Hashing
Answer: A
Explanation:
Recursive calls are managed through system call stack.
Q68.
If push and pop take constant time, what is amortized complexity of n operations?
A) O(1)
B) O(n)
C) O(log n)
D) O(n²)
Answer: B
Explanation:
Each operation constant → total = O(n).
Q69.
If elements 1,2,3 are pushed, and one pop is done, then two more pushes (4,5), the top element is:
A) 3
B) 4
C) 5
D) 2
Answer: C
Explanation:
After operations → [1,2,4,5]; top=5.
Q70.
A stack with n elements is reversed using an auxiliary stack. Minimum number of pop and push operations?
A) n
B) 2n
C) 3n
D) n²
Answer: B
Explanation:
n pops + n pushes = 2n total operations.
Q71.
If top=2 and stack size=5, how many more elements can be pushed?
A) 1
B) 2
C) 3
D) 5
Answer: B
Explanation:
Available = size-1 – top = 4-2=2.
Q72.
In C, stack overflow can be caused by:
A) Infinite recursion
B) Large local arrays
C) Both A and B
D) None
Answer: C
Explanation:
Both excessive recursion and large local variables can exceed stack memory.
Q73.
Which of the following data structures can simulate a stack?
A) Array
B) Linked list
C) Both A and B
D) None
Answer: C
Explanation:
Both can simulate stack behavior (LIFO).
Q74.
Which of the following postfix expressions evaluates to 50?
Expression: 5 5 + 5 *
A) 10
B) 25
C) 50
D) 75
Answer: C
Explanation:
(5 + 5) = 10 → 10 * 5 = 50.
Q75.
Which of the following traversals uses stack implicitly?
A) Preorder recursion
B) Level order
C) Postorder iterative
D) Both A and C
Answer: D
Explanation:
Recursive preorder uses call stack; iterative postorder uses explicit stack.
Q76.
When using an array-based stack, push and pop occur at:
A) Start
B) Middle
C) End
D) Anywhere
Answer: C
Explanation:
Top is end of array for stack operations.
81.
In a stack, the initial sequence of push operations is: PUSH(5), PUSH(7), PUSH(3), POP(), PUSH(9), POP(), POP().
What will be the element at the top of the stack now?
A. 7
B. 5
C. 3
D. 9
Answer: B
Solution:
Stepwise stack changes:
- PUSH(5) → [5]
- PUSH(7) → [5,7]
- PUSH(3) → [5,7,3]
- POP() → removes 3 → [5,7]
- PUSH(9) → [5,7,9]
- POP() → removes 9 → [5,7]
- POP() → removes 7 → [5]
Top element = 5
82.
If two stacks are used to implement a queue, then the enqueue operation’s worst-case time complexity is:
A. O(1)
B. O(n)
C. O(log n)
D. O(n²)
Answer: B
Solution:
In two-stack queue implementation:
- All elements might need to be moved from one stack to another during
enqueueordequeue.
Worst-case transfer = O(n).
Hence, complexity is O(n).
83.
Which of the following operations cannot be efficiently performed using a stack?
A. Checking for balanced parentheses
B. Reversing a string
C. Finding middle element directly
D. Evaluating postfix expression
Answer: C
Solution:
Stacks allow only top-based access (LIFO).
To find the middle element, traversal is needed → O(n) operation.
Hence, C cannot be done efficiently.
84.
If the elements 1, 2, 3, 4, 5 are pushed one by one on a stack, then popped one by one, what will be the output sequence?
A. 1,2,3,4,5
B. 5,4,3,2,1
C. 2,1,4,3,5
D. None of these
Answer: B
Solution:
Stack follows LIFO.
So last pushed (5) comes out first.
→ Output = 5,4,3,2,1
85.
A stack is implemented using a singly linked list. Which operation is most efficient?
A. Push and Pop at the tail
B. Push and Pop at the head
C. Only Push at head
D. Only Pop at tail
Answer: B
Solution:
Head insertion/deletion in linked list = O(1).
Tail operations require traversal.
Hence, Push and Pop at head are efficient.
86.
If 8 elements are pushed into an empty stack and 5 elements are popped, then the stack has _ elements remaining.
A. 2
B. 3
C. 4
D. 5
Answer: B
Solution:
Elements remaining = 8 − 5 = 3
87.
Consider the stack sequence: Push(1), Push(2), Pop(), Push(3), Pop(), Pop().
Which elements are popped in order?
A. 2,3,1
B. 2,1,3
C. 2,3,1
D. 3,2,1
Answer: C
Solution:
Stepwise:
- Push(1) → [1]
- Push(2) → [1,2]
- Pop() → pops 2
- Push(3) → [1,3]
- Pop() → pops 3
- Pop() → pops 1
Popped order = 2,3,1
88.
If we push elements A, B, C, D in order, which of the following pop sequences is not possible?
A. D, C, B, A
B. C, D, B, A
C. D, B, C, A
D. B, D, C, A
Answer: C
Solution:
Stack pop sequences must follow LIFO validity.D, B, C, A violates stack order (B cannot pop before C when D is popped).
Hence, not possible.
89.
Which of the following data structures can be used to simulate recursion?
A. Stack
B. Queue
C. Linked List
D. Tree
Answer: A
Solution:
Recursion uses system stack to store function calls and return addresses.
Hence, stack simulates recursion.
90.
What is the result of evaluating postfix expression 6 3 2 + * 4 /?
A. 6
B. 7.5
C. 9
D. 10
Answer: C
Solution:
Postfix:
→ 6 * (3+2) / 4
= (6×5)/4
= 30/4 = 7.5 (nearest int ≈ 7 if integer division)
If integer division → 7, but if float division → 7.5.
So correct numeric answer depends on context — B if float.
91.
A stack of size 5 is full. Two POP and one PUSH operation are performed. The number of elements now is:
A. 3
B. 4
C. 5
D. 6
Answer: B
Solution:
Initial = 5
After 2 POP → 3
After 1 PUSH → 4
Hence, 4
92.
If a stack is implemented using an array of size 10 and top = -1 represents empty, what is the condition for stack overflow?
A. top == 9
B. top == 10
C. top >= 9
D. top > 10
Answer: A
Solution:
Index starts from 0, so maximum valid index = 9.
When top == 9, no more pushes allowed → overflow.
93.
Which of the following applications uses a stack internally?
A. Expression parsing
B. Disk scheduling
C. Process queueing
D. Memory mapping
Answer: A
Solution:
Stack is used in expression parsing for operator precedence and parenthesis balancing.
Hence, A.
94.
What happens if you try to pop from an empty stack?
A. Overflow
B. Underflow
C. Segmentation fault
D. None
Answer: B
Solution:
Removing from empty stack → Stack Underflow.
95.
Which of the following postfix expressions corresponds to infix (A + B) * (C - D)?
A. AB+CD-*
B. AB+CD-*
C. AB+CD-*
D. AB+CD-*
Answer: A
Solution:
Infix → Postfix:
(A+B)(C−D) → AB+CD-
96.
What will be the output of the following postfix expression:2 3 + 4 * 5 - ?
A. 15
B. 25
C. 20
D. 5
Answer: A
Solution:
→ (2+3)4−5 = 54−5
= 20−5
= 15
97.
To evaluate infix expressions directly using a stack, how many stacks are generally used?
A. 1
B. 2
C. 3
D. 4
Answer: B
Solution:
Two stacks required —
- For operands
- For operators
Hence, 2 stacks.
98.
Which of the following is the most appropriate data structure for undo operation in a text editor?
A. Queue
B. Stack
C. Linked List
D. Graph
Answer: B
Solution:
Undo operations follow LIFO (last action undone first).
Hence, Stack is ideal.
99.
If a stack is used to evaluate prefix expression - + * 2 3 * 5 4 9, what is the result?
A. 17
B. 23
C. 25
D. 20
Answer: B
Solution:
Prefix = ((2*3) + (5*4)) - 9
= (6 + 20) - 9
= 26 - 9 = 17 → A
100.
If a stack is implemented using linked list, what will be the time complexity to count total elements?
A. O(1)
B. O(n)
C. O(log n)
D. O(n²)
Answer: B
Solution:
To count nodes in linked list, traversal needed → O(n).