LearnViz CompSci
Home / Learn / Data Structures / Deque

Beginner Topic 8 of 52 Data Structures

Deque

Double-ended queue permitting insertion and removal at both ends.

How it works

A double-ended queue supports O(1) insertion and removal at both the front and the back. It is commonly implemented as a circular array or a doubly linked list, and it generalizes both stacks and queues because it can be used as either. Some implementations also support random access by index.

Where it is used

Sliding-window maximum algorithms, work-stealing schedulers, palindrome checks, undo buffers with bounded history and breadth-first search variants such as 0-1 BFS use deques. Python collections.deque and C++ std::deque are standard.

Common pitfall

Choosing a plain array or list for front insertions makes them O(n). Using a deque when you only need one end adds overhead. Be consistent about which end is front and which is back, and note that middle insertion is not constant time.

Where it fits in the course

Deque is topic 8 of 52 in Data Structures, rated Beginner. It follows Queues. The next topic is Priority Queue.

Practice and explore

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. Check your understanding in the Data Structures quiz, and revisit the topic if you miss a question.

Frequently asked questions

What is Deque?
Double-ended queue permitting insertion and removal at both ends. It belongs to Data Structures and is a beginner-level topic.
Where do people use Deque?
Sliding-window maximum algorithms, work-stealing schedulers, palindrome checks, undo buffers with bounded history and breadth-first search variants such as 0-1 BFS use deques.
What is the most common mistake with Deque?
Choosing a plain array or list for front insertions makes them O(n).
What should I learn before this topic?
Start with Queues, the topic just before it in Data Structures.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Data Structures quiz. You can also explore Stack, Queue & Linked List in the Visual Lab.
Is Deque hard to learn?
It is a Beginner topic, so it works as an entry point. If the terms are new, read the explanation twice and try the visualizer before the quiz.
How long does it take to learn Deque?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to Deque?
Queues, Priority Queue, Stacks are closely connected. The full list is in the related topics section of this page.
What should I study after Deque?
Continue with Priority Queue, the next topic in Data Structures.

Related topics