Consider the following statements : S₁ : A queue can be implemented using two stacks. S₂ : A stack can be implemented using two queues. Which of the…
Consider the following statements : S₁ : A queue can be implemented using two stacks. S₂ : A stack can be implemented using two queues. Which of the following is correct?
Show answerHide answer
Correct answer: (C) Both S₁ and S₂ are correct
Explanation
A queue can be implemented using two stacks S1 and S2: enqueue pushes onto S1; for dequeue, if S2 is not empty pop from it, otherwise first pop all elements of S1 and push them into S2, then pop from S2. So S₁ is correct. Similarly, a stack can be implemented using two queues, so S₂ is also correct. Hence, the answer is option (c).