Minimum number of queues to implement stack is . . . . . . . .
A. 3
B. 4
C. 1
D. 2
Answer: Option D
Solution (By Examveda Team)
A stack can be implemented using two queues.In a stack, the Last In First Out (LIFO) principle is followed, while in a queue, the First In First Out (FIFO) principle is used.
To implement stack operations using queues, we need two queues — one to hold the elements temporarily and the other to help reverse the order of insertion.
When performing a push operation, elements are enqueued in such a way that the newly added element appears at the front of the queue, simulating stack behavior.
Alternatively, we can also implement the pop operation by moving elements between the two queues until we reach the desired element to remove.
Hence, the minimum number of queues required to implement a stack is 2.
Join The Discussion
Comments (1)
Related Questions on Introduction to Data Structures
A. A collection of data values
B. A programming language
C. A set of algorithms
D. A way of organizing and storing data

wrong answer answer is 2