The GATE Grind

GATE 2021 CS (CS1) – Question 31

Programming and Data Structures · Stacks and Queues · 1 mark · Numerical answer

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 ______.

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 86

Explanation

**Stack** (LIFO): `push(54)`, `push(52)`, `pop()` removes 52, `push(55)`, `push(62)`, `s = pop()` removes the top, 62. So $s=62$.

**Queue** (FIFO): `enqueue(21)`, `enqueue(24)`, `dequeue()` removes 21, `enqueue(28)`, `enqueue(32)`, `q = dequeue()` removes the head, 24. So $q=24$.

$s+q=62+24=\mathbf{86}$.

More Stacks and Queues questions

All Stacks and Queues questions →