Skip to content
GATEiit

GATE CSE 2021 Set 1 Q31: Stack pop plus queue dequeue after a sequence of operations

Question

Consider the following sequence of operations on an empty stack.

push(54); push(52); pop(); push(55); push(62); s = pop();

Consider the following sequence of operations on an empty queue.

enqueue(21); enqueue(24); dequeue(); enqueue(28); enqueue(32); q = dequeue();

The value of s + q is ________.

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 86 (official GATE 2021 final answer key)

Concept used: A stack is last-in first-out; a queue is first-in first-out.

First step: Trace each structure: the final pop returns the most recently pushed value, the final dequeue the oldest value still queued.

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 2021 Set 1 CS question paper and final answer key, organised by IIT Bombay. Question paper · Answer key