The fundamental operations in a double-ended queue D are: insertFirst(e) –…

2024

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

Attempted by 135 students.

Show answer & explanation

Correct answer: 17

Final answer: 17

Work through the operations step by step (deque shown as [front ... back]):

  • Start: []

  • insertFirst(10) → [10]

  • insertLast(32) → [10, 32]

  • a ← removeFirst() removes 10, so a = 10; deque → [32]

  • insertLast(28) → [32, 28]

  • insertLast(17) → [32, 28, 17]

  • a ← removeFirst() removes 32, so a = 32; deque → [28, 17]

  • a ← removeLast() removes 17, so a = 17; deque → [28]

Therefore the final value of a is 17.

Explore the full course: Gate Guidance By Sanchit Sir