GATE CS 2024 · Set-2 · Arrays & Matrix Representation

MSQ · 2 marks · Problem PROG-DSTR-0087

Let S1 and S2 be two stacks. S1 has capacity of 4 elements. S2 has capacity of 2 elements. S1 already has 4 elements: 100, 200, 300, and 400, whereas S2 is empty, as shown below.\[\begin{array}{|c|} \hline 400 (Top) \\ \hline 300 \\ \hline 200\\ \hline 100 \\ \hline \end{array}\]Stack S1\[\begin{array}{|c|} \hline \\ \hline \\ \hline \end{array}\]Stack S2Only the following three operations are available:PushToS2: Pop the top element from S1 and push it on S2.PushToS1: Pop the top element from S2 and push it on S1.GenerateOutput: Pop the top element from S1 and output it to the user.Note that the pop operation is not allowed on an empty stack and the push operation is not allowed on a full stack.Which of the following output sequences can be generated by using the above operations?
  1. A
    100, 200, 400, 300
  2. B
    200, 300, 400, 100
  3. C
    400, 200, 100, 300
  4. D
    300, 200, 400, 100

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solutionOfficial GATE Answer Key: B, C, D.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/422859/gate-cse-2024-set-2-question-38

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com