The minimum number of stacks needed to implement a queue is
2017
The minimum number of stacks needed to implement a queue is
- A.
3
- B.
1
- C.
2
- D.
4
Attempted by 791 students.
Show answer & explanation
Correct answer: C
To implement a queue using stacks, you need at least two stacks. One stack is used for enqueue operations (pushing elements), and the second stack is used for dequeue operations. When dequeuing, if the output stack is empty, all elements from the input stack are transferred to the output stack, reversing their order to achieve FIFO behavior. Therefore, the minimum number of stacks required is 2.
A video solution is available for this question — log in and enroll to watch it.