Examveda

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.

This Question Belongs to Data Structure >> Introduction To Data Structures

Join The Discussion

Comments (1)

  1. Vishal Lazrus
    Vishal Lazrus:
    1 week ago

    wrong answer answer is 2

Related Questions on Introduction to Data Structures