Skip to content
GATEiit

GATE CSE 2026 Session 2 Q50: Stack/queue assignments that produce the output 4 3 1 2 5

Question

Consider a stack SS and a queue QQ. Both of them are initially empty and have the capacity to store ten elements each. The elements 1, 2, 3, 4, and 5 arrive one by one, in that order. When an element arrives, it is assigned either to SS (pushed on SS) or to QQ (enqueued to QQ). Once all the five elements are stored, the output is generated in two steps. First, stack SS is emptied by popping all elements. Then queue QQ is emptied by dequeueing all elements. The output obtained by following this process is 4 3 1 2 5.

Given the output, the objective is to predict whether an element was assigned to SS or QQ.

Which of the following options is/are possible valid assignment(s) of the elements?

Note: In the options, the notation xSx_S denotes that element xx was assigned to SS and yQy_Q denotes that element yy was assigned to QQ.

Try it: multiple select: one or more correct options

Select one or more options
Select all correct options. No negative marking, no partial marks.
Show answer and explanation

Answer: A, B (official GATE 2026 final answer key)

Concept used: The stack outputs its elements in decreasing arrival order, then the queue in increasing order.

First step: Simulate each option: pop the stack elements in reverse order, then append the queue elements in order, and compare with 4 3 1 2 5.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2026 Session 2 CS question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key