GATE CS 2026 (Afternoon) — Question 50

Data StructuresAbstract Data Types (ADTs), Stacks, QueuesMSQ2 marksMedium

Consider a stack \( S \) and a queue \( Q \). 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 \( S \) (pushed on \( S \)) or to \( Q \) (enqueued to \( Q \)). Once all the five elements are stored, the output is generated in two steps. First, stack \( S \) is emptied by popping all elements. Then queue \( Q \) 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 \( S \) or \( Q \). Which of the following options is/are possible valid assignment(s) of the elements? Note: In the options, the notation \( xS \) denotes that element \( x \) was assigned to \( S \) and \( yQ \) denotes that element \( y \) was assigned to \( Q \).
  1. A
    \( 1S, 2Q, 3S, 4S, 5Q \)
  2. B
    \( 1Q, 2Q, 3S, 4S, 5Q \)
  3. C
    \( 1Q, 2Q, 3Q, 4S, 5S \)
  4. D
    \( 1S, 2S, 3S, 4Q, 5Q \)
Practise the full 2026-AN paper
Challenge a friend: WhatsApp Telegram
Recommended book · affiliate linkIntroduction to Algorithms (CLRS)The standard reference behind most GATE algorithm questions.
Practise more on Abstract Data Types (ADTs), Stacks, QueuesTimed, in the real exam interface · free to start

A GATE question every morning

One real past-paper question every morning for your branch, answer hidden until you tap. Free on Telegram.

Join
Stuck? Ask in the student group