Queue is an abstract data type following the First In First Out behaviour, where all element additions happen at the end (enqueue operation) and all element removals happen at the front of the queue (dequeue operation). It’s a linear data structure and can be implemented using an Array or a Linked List

Time Complexity

OperationBig-O
Enqueue/OfferO(1)
Dequeue/PollO(1)
FrontO(1)
BackO(1)
isEmptyO(1)

Common Problems

Using Arrays

In languages without built-in queue structure (JS, python), you can arrays or lists, but such implementation will have O(n) operations because of needing to shift an array.

Corner Cases

  • empty queue
  • one item
  • two items