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
- Open the interactive lesson, with a mini quiz.
- Take the Data Structures quiz.
- Explore the Stack, Queue & Linked List visualizer: Push, pop, enqueue and dequeue interactively.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Data Structures quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Deque?
Where do people use Deque?
What is the most common mistake with Deque?
What should I learn before this topic?
How can I practice it?
Is Deque hard to learn?
How long does it take to learn Deque?
Which topics are related to Deque?
What should I study after Deque?
Related topics
- Queues (Data Structures)
- Priority Queue (Data Structures)
- Stacks (Data Structures)
- Hash Tables (Data Structures)