Skip to content
Exercises · Q6

Q.Show the status of queue after each operation
enqueue(34)
enqueue(54)
dequeue()
enqueue(12)
dequeue()
enqueue(61)
peek()
dequeue()
dequeue()
dequeue()
dequeue()
enqueue(1)

Odisha ChseTextbookSubjective· 3mImportance★★★★★
71% · 10/14 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

This is a queue trace problem. We simulate a FIFO (First-In-First-Out) queue step by step, showing the front and rear after each operation, and note when operations fail due to an empty queue.

Why a Queue?

A queue is the right data structure here because the problem explicitly asks for queue operations. The key idea: FIFO — the element that has been in the queue the longest (the front) is the one removed by dequeue(). New elements join at the rear. peek() returns the front element without removing it.

We'll maintain a simple list-based queue where:

  • front is index 0
  • rear is the last index
  • enqueue(x) appends to the end
  • dequeue() removes from index 0 (and shifts everything left)
  • peek() returns the element at index 0

Let's trace each operation.

OperationQueue State (front → rear)FrontRearNotes
Initial[]——Empty queue
enqueue(34)[34]3434First element
enqueue(54)[34, 54]345454 joins at rear
dequeue()[54]5454Removes 34 (front)
enqueue(12)[54, 12]541212 joins at rear
dequeue()[12]1212Removes 54 (front)
enqueue(61)[12, 61]126161 joins at rear
peek()[12, 61]1261Returns 12, queue unchanged
dequeue()[61]6161Removes 12 (front)
dequeue()[]——Removes 61 (front), queue now empty
dequeue()[]——Underflow! Queue is empty — operation fails
dequeue()[]——Underflow! Still empty

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.