Time Complexity of Queue Operations


Queues follow the First-In First-Out (FIFO) principle, which determines how elements are inserted and removed. Each operation — like enqueue, dequeue, or checking the front — typically has a constant-time complexity, making queues efficient for ordered data processing. In this guide, we explore the time complexities of five core queue operations.

Summary Table

Operation Best Case Average Case Worst Case
Enqueue O(1) O(1) O(1)
Dequeue O(1) O(1) O(1)
Peek O(1) O(1) O(1)
isEmpty O(1) O(1) O(1)
Size O(1) O(1) O(1)

1. Enqueue

The enqueue operation adds an element to the rear of the queue.

2. Dequeue

The dequeue operation removes an element from the front of the queue.

3. Peek

The peek operation retrieves the front element without removing it.

4. isEmpty

The isEmpty operation checks whether the queue is empty.

5. Size

The size operation returns the number of elements in the queue.