◀ frontback ▶
Empty deque — push to either end.
AlgoPlus//structures / deque
Read the theory

Deque · Double-Ended Queue

Push and pop at both the front and the back — O(1) everywhere.

Size
3
Legend
Added
Removed
Element
AI Tutor Workspace
In a nutshell
A deque — short for double-ended queue — is a line you can add to or remove from at either end, the front or the back, each in constant time. That makes it a stack and a queue rolled into one: use one end and it behaves Last-In-First-Out, use both in the usual way and it's First-In-First-Out. The flexibility suits things like a browser's back-and-forward history or a fixed-size window sliding over data.
Ready
Press play to begin the cinematic walkthrough.
A double-ended queue lets you push and pop at both ends in O(1) — a stack and a queue in one structure.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Deque · Double-Ended Queue.