Double-Ended Queue

Double-Ended Queues are also called Deques. Going by the name, you might have already guessed what a Deque is. A Deque is a queue at both ends. That means, you can take out the elements on either end and add one from either end too. However you cannot remove or add elements between any two elements of the queue.

How does the Deque work?

How do you add an element to the Deque?

You can add an element on either end of the queue.

How do you remove an element from the Deque?

You can delete an element from either end of the queue

Rules of the Deque

The Deque has two operations:

  1. Add a new element: You can insert one element at either end of the queue.
  2. Remove an element: You can remove one element from either end of the queue.

There is one restriction though: You may not remove an element from anywhere in the middle of the deque.

Extra restrictions can be placed on the Deque - one of the operations from adding and removing an element can be restricted to one side only. For example, you can have a deque wherein you can add elementson both ends but can remove them from only one end!

Usage

Deques are used in scheduling algorithms. You can also develop your own use-case for a Deque.

Updated: