Skip to content

ISRO Scientist/Engineer CSE 2017Data Structures › Stacks and Expression Evaluation

ISRO Scientist/Engineer CSE 2017 PYQ: The minimum number of stacks needed to implement a queue is

The minimum number of stacks needed to implement a queue is

  1. A
    3
  2. B
    1
  3. C
    2
    Correct answer
  4. D
    4

Answer

(C) $2$

Approach

A queue is FIFO while a stack is LIFO. To reverse the order, we need one stack to hold elements in original order and a second stack to reverse them during dequeue. Hence two stacks suffice, and one stack cannot implement a queue because a single stack cannot reverse order without extra storage.

Reviewed by ISRO IQ Editorial Team.