Consider the following sequence of operations on an empty stack.…
2021
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 ________.
Attempted by 171 students.
Show answer & explanation
Correct answer: 86
Key idea: a stack is Last-In-First-Out (LIFO) and a queue is First-In-First-Out (FIFO).
Stack operations (start empty): Push(54) → [54]; push(52) → [54, 52]; pop() removes 52 → [54]; push(55) → [54, 55]; push(62) → [54, 55, 62]; s = pop() removes 62, so s = 62.
Queue operations (start empty): enqueue(21) → [21]; enqueue(24) → [21, 24]; dequeue() removes 21 → [24]; enqueue(28) → [24, 28]; enqueue(32) → [24, 28, 32]; q = dequeue() removes 24, so q = 24.
Therefore s + q = 62 + 24 = 86.
A video solution is available for this question — log in and enroll to watch it.