Queue (FIFO)

First In First Out (FIFO) - Elements are added at rear and removed from front

Max:
Speed:
Element
Front
Rear

Enqueue (Add to Rear)

Add element to rear - O(1)

Dequeue (Remove from Front)

Remove and return front element - O(1)*

*Using array shift() for simplicity

Peek (View Front)

View front element without removing - O(1)

Query Operations

About Queue

FIFO Principle: First In, First Out - the oldest element is removed first.

Time Complexity:

  • Enqueue: O(1)
  • Dequeue: O(1) with circular array
  • Peek: O(1)

Use Cases: Task scheduling, print queue, breadth-first search, message queuing