GATE CS 2026 Set 2 | Question 50
Programming & Data Structures › Stacks & Queues · MSQ · 2 marks · Answer: A, B
- Question 50Programming & Data Structuresmsq2 marksConsider a stack and a queue , both initially empty with capacity ten. The elements 1,2,3,4,5 arrive one by one in that order; each is assigned to (pushed) or (enqueued). After all five are stored, output is generated by first popping all of , then dequeueing all of . The output obtained is . Given the output, predict whether each element went to or . Which of the following is/are possible valid assignment(s)? Note: means was assigned to and means was assigned to .
- A.✓
- B.✓
- C.
- D.
Answer: A, B
Solution
Answer: (A), (B) Popping gives the reverse of its push order; dequeuing gives its arrival order. Output (reverse of ) then (). - (A) pop ; → ✓ - (B) pop ; → ✓ - (C) ✗ - (D) ✗ - A.
More GATE PYQ on Stacks & Queues
All GATE CS Programming & Data Structures PYQ →Attempt GATE CS 2026 Set 2 in real GATE exam mode
Full paper with a timer, the GATE interface and a topic-wise analysis — free.
Create free account →