Skip to main contentSkip to solution

In a queue following operations were performed:

enqueue(8), enqueue(4), dequeue(), enqueue(7), enqueue(15), dequeue(), enqueue(18), dequeue(), enqueue(8), enqueue(4).

What will be the order of the elements in the queue starting from rear to front?

(A) 15

(B) 4

(C) 18

(D) 8

Solution

✅ Correct Option: 3

A queue is FIFO: elements are added at the rear and removed from the front.

OperationQueue (front to rear)
enqueue(8)8
enqueue(4)8, 4
dequeue() removes 84
enqueue(7)4, 7
enqueue(15)4, 7, 15
dequeue() removes 47, 15
enqueue(18)7, 15, 18
dequeue() removes 715, 18
enqueue(8)15, 18, 8
enqueue(4)15, 18, 8, 4

The final queue from front to rear is 15, 18, 8, 4, so from rear to front the order is:

(B) 4

(D) 8

(C) 18

(A) 15


Option 1: lists the elements in the front-to-back order of insertion of the labels, not the queue's rear-to-front order.

Option 4: places 18 at the rear, but 18 was enqueued before the last 8 and 4.

Keyboard Shortcuts

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