⬅ Previous Topic
Time Complexity of Queue OperationsNext Topic ⮕
Singly Linked List Introduction⬅ Previous Topic
Time Complexity of Queue OperationsNext Topic ⮕
Singly Linked List IntroductionSpace complexity refers to the amount of extra memory used by an operation relative to the input size. In queues, most operations are performed in-place, which means they operate directly within the existing structure without requiring additional memory. Below, we explore the space complexity of key queue operations: Enqueue, Dequeue, Peek, isEmpty, and Size.
Operation | Space Complexity | Why? |
---|---|---|
Enqueue | O(1) | Element is added to the rear using constant space |
Dequeue | O(1) | Element is removed from the front without new memory |
Peek | O(1) | Accesses the front element directly |
isEmpty | O(1) | Checks size or front/rear pointer |
Size | O(1) | Returns a maintained count variable |
The enqueue operation inserts a new element at the rear of the queue.
O(1)
The dequeue operation removes the element from the front of the queue.
O(1)
The peek operation retrieves the front element without removing it.
O(1)
The isEmpty operation checks if the queue is empty.
O(1)
The size operation returns the number of elements in the queue.
O(1)
⬅ Previous Topic
Time Complexity of Queue OperationsNext Topic ⮕
Singly Linked List IntroductionYou 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.