Skip to main content

What is the time complexity of inserting into a queue?

The time complexity of the enqueue (insertion into a queue) operation is usually O(1), meaning it runs in constant time.

This is because the element is simply added to the end of the queue, without needing to traverse the whole list.

Exception: if the queue is implemented on a fixed-size array and it needs to be resized, then at the moment of memory reallocation the operation can take O(n), but this happens rarely (in the amortized sense, the complexity stays O(1)).

Short Answer

Interview ready
Premium

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