Skip to content
GATEiit

GATE DA 2024 Q32: Trace operations on a double-ended queue

Question

The fundamental operations in a double-ended queue D are:

insertFirst(e) – Insert a new element e at the beginning of D.

insertLast(e) – Insert a new element e at the end of D.

removeFirst() – Remove and return the first element of D.

removeLast() – Remove and return the last element of D.

In an empty double-ended queue, the following operations are performed:

insertFirst(10)
insertLast(32)
a ← removeFirst()
insertLast(28)
insertLast(17)
a ← removeFirst()
a ← removeLast()

The value of a is ______.

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 17 (official GATE 2024 final answer key)

Concept used: Deque simulation: track the contents after each operation.

First step: After the first three operations D = [32]; then [32, 28, 17]; removeFirst leaves [28, 17], and removeLast returns the last element.

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 2024 DA question paper and final answer key, organised by IISc Bangalore. Question paper · Answer key