⬅ Previous Topic
Queue OperationsNext Topic ⮕
Space Complexity of Queue Operations⬅ Previous Topic
Queue OperationsNext Topic ⮕
Space Complexity of Queue OperationsQueues 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.
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) |
The enqueue operation adds an element to the rear of the queue.
The dequeue operation removes an element from the front of the queue.
The peek operation retrieves the front element without removing it.
The isEmpty operation checks whether the queue is empty.
The size operation returns the number of elements in the queue.
count
variable.⬅ Previous Topic
Queue OperationsNext Topic ⮕
Space Complexity of Queue OperationsYou can support this website with a contribution of your choice.
When making a contribution, mention your name, and programguru.org in the message. Your name shall be displayed in the sponsors list.