In which sequence the operations are allowed to result in a queue with:
X C V
Where the original array to be inserted was:
Z X C V
A. enqueue(Z)
B. dequeue()
C. enqueue(C)
D. enqueue(V)
E. enqueue(X)
In which sequence the operations are allowed to result in a queue with:
| X | C | V |
|---|
Where the original array to be inserted was:
| Z | X | C | V |
|---|
A. enqueue(Z)
B. dequeue()
C. enqueue(C)
D. enqueue(V)
E. enqueue(X)
Solution
A queue is FIFO (first in, first out): items are added at the rear and removed from the front. The original order Z, X, C, V must be enqueued in that order, and the one dequeue must remove Z from the front.
Enqueueing Z, X, C, V (A, E, C, D) gives Z, X, C, V, and then dequeue() (B) removes Z, leaving X, C, V.
Option 2: dequeue() runs right after enqueue(Z), so Z is removed immediately. The remaining enqueues give V, C, X, which is the wrong order.
Option 3: dequeue() is called on an empty queue, which is underflow.
Option 4: enqueue(C) then dequeue() removes C, not Z. The final queue is V, Z, X.
Related questions:
2025: 22 May Shift 1
2026: 19 May Shift 1
2026: 20 May Shift 1