Lesson 035

Queue Operations

Enqueue & Dequeue · FIFO

1:00

How queues work — enqueue at the rear, dequeue from the front, FIFO ordering, edge-case guards, and why a circular buffer keeps both operations O(1).

By the end, you can

  • Explain FIFO and distinguish a queue from a stack.
  • Trace enqueue and dequeue operations on a concrete queue and predict the final state.
  • Use peek(), isEmpty(), and isFull() correctly and state their time complexity.
  • Identify underflow and overflow conditions and describe the appropriate guards.
  • Explain why naive array dequeue is O(n) and how a circular buffer avoids that cost.
  • Compute the next index after a wrap in a ring buffer using the expression `(i + 1) % SIZE`.
  • Describe why front == rear is ambiguous in a circular buffer and how a count variable resolves it.
  • List the correct sequence of steps for a circular-buffer enqueue and dequeue.
  • Give three real-world systems that use queues and explain why FIFO is the right ordering for each.
Up next in Linear Data Structures
Questions or feedback?