GATE CS 2024 Set 2 | Question 48

Programming & Data Structures › Stacks & Queues · MSQ · 2 marks · Answer: B, C, D

  1. Question 48Programming & Data Structuresmsq2 marks
    S1 (capacity 4) holds 100,200,300,400 (400 top); S2 (capacity 2) empty. Operations: PushToS2 (S1->S2), PushToS1 (S2->S1), GenerateOutput (pop S1 to output). No pop on empty / push on full. Which output sequences can be generated?
    • A.
      100, 200, 400, 300
    • B.
      200, 300, 400, 100
      ✓
    • C.
      400, 200, 100, 300
      ✓
    • D.
      300, 200, 400, 100
      ✓

    Answer: B, C, D

    Solution

    Answer: (B), (C) and (D) This is a stack-permutation question with the auxiliary stack S2 (capacity 2) allowing limited reordering. Simulating the allowed moves, sequences (B) 200,300,400,100, (C) 400,200,100,300, and (D) 300,200,400,100 are each reachable, while (A) 100,200,400,300 cannot be produced under the capacity constraints.

More GATE PYQ on Stacks & Queues

All GATE CS Programming & Data Structures PYQ →

Attempt GATE CS 2024 Set 2 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →