Skip to main content

What operations does a deque support?

A deque (double-ended queue) supports the following main operations, all in O(1):

  1. addFront(x): add element x to the front.
  2. addRear(x): add element x to the back.
  3. removeFront(): remove and return the element from the front.
  4. removeRear(): remove and return the element from the back.
  5. peekFront(): look at the first element without removing it.
  6. peekRear(): look at the last element without removing it.
  7. isEmpty(): check whether the queue is empty.
  8. size(): return the number of elements (sometimes added).

Thanks to access from both sides, a deque can be used both as a queue (FIFO) and as a stack (LIFO).

Short Answer

Interview ready
Premium

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