Skip to main content

What is the time complexity of removing from a queue?

The time complexity of the dequeue (removal from a queue) operation is O(1).

This is because the element is always removed from the front of the queue, and this does not require traversing the whole list: it is enough to just move a pointer (or take the first element, if the queue is implemented as a linked list or a circular buffer).

Exception: if the queue is implemented on a plain array without a circular structure and elements are physically shifted on removal, then the complexity becomes O(n). That is why circular buffers or linked lists are used in practice to keep O(1).

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.