Skip to content

Computer Science · Ch 4 — Queue

Introduction to Deque

4.4

Introduction to Deque

A deque (pronounced “deck”) is a data structure where elements can be added or removed from either end — the front (head) or the rear (tail). Unlike a standard queue or stack, a deque does not force you to pick one side for insertion and the opposite side for deletion. You can push or pop from both ends freely.

Because of this flexibility, a deque can be used to implement either a stack or a queue in a program. If you restrict operations to only one end, it behaves like a stack (LIFO). If you allow insertion at one end and deletion from the other, it behaves like a queue (FIFO). The deque itself does not impose either restriction — it is a general-purpose double-ended structure.

The name “deque” is short for double-ended queue. The basic structure has two ends labelled front (head) and rear (tail), and both ends support two operations:

  • Push (insertion) — can happen at the front or the rear.
  • Pop (deletion) — can happen at the front or the rear.

Figure 4.4 in the textbook illustrates this: the front end shows both a push and a pop arrow, and the rear end also shows both a push and a pop arrow. This symmetry is what makes the deque different from a simple queue or stack. …

Figure 4.4Basic deque structure displaying head and tail to implement stack or queue.
Fig. 4.4 — Basic deque structure displaying head and tail to implement stack or queue.

Drawn by us to help you understand the concept clearly, and verified to make sure it's accurate. For exams, practice from your NCERT textbook's own diagram.

A deque (double-ended queue) is a queue that relaxes the single-entry-point rule: insertion (Push) and deletion (Pop) are both allowed at EITHER end — the Front and the Rear — not just insert-at-rear/delete-at-front like an ordinary queue.

That's why the figure shows two separate arrows at each end: at the Front, one arrow for Push (adding an element there) and one for Pop (removing from there); the Rear end mirrors this with its own Push and Pop arrows. Because both ends support both operations, a deque is flexible enough to behave like a stack (if you only ever push/pop from one end) o …