Skip to main contentSkip to solution

After the following sequence of operations, what will be the order of elements removed from a queue?

ENQUEUE(2)

ENQUEUE(4)

ENQUEUE(8)

DEQUEUE()

ENQUEUE(10)

DEQUEUE()

Solution

✅ Correct Option: 2

A queue follows FIFO (First In, First Out), so elements leave in the same order they entered.

OperationQueue (front to rear)Removed
ENQUEUE(2)2-
ENQUEUE(4)2, 4-
ENQUEUE(8)2, 4, 8-
DEQUEUE()4, 82
ENQUEUE(10)4, 8, 10-
DEQUEUE()8, 104

The elements removed, in order, are 2, 4.


Options 1, 3 and 4: these take the most recently added items (LIFO, as in a stack), but a queue always removes from the front. 8 and 10 are still in the queue at the end.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question