Deque (Double-Ended Queue) – (Types, Examples, Characteristics, Applications)
A deque (short for Double-Ended Queue) is a linear data structure that allows the insertion and deletion of elements from both ends (front, and rear). Unlike a standard queue or stack, a deque is more versatile and can function as both (a stack or a queue) depending on how it is used.
Characteristics of Deque
- Bidirectional Operations: Insertions and deletions can occur at both ends (front and rear).
- Dynamic Size: Its size can grow or shrink dynamically as required.
- No Fixed Restrictions: There are no restrictions on the number of operations at either end.
Types of Deques
There are two major types of deque
1. Input-Restricted Deque
This deque type restricts the insertion operation, but it is flexible when removing elements.
- Insertion is allowed only at one end (either the front or rear).
- Deletion is allowed from both ends (front and rear).
The following figure explains it in detail
2. Output-Restricted Deque
This deque type restricts the deletion operation, but it is flexible when adding elements.
- Deletion is allowed only at one end (either the front or rear).
- Insertion is allowed at both ends.

Applications of Deque
- Sliding Window Problems: Deques are often used to find the maximum or minimum in a sliding window efficiently.
- Palindrome Checking: Deques allow checking characters from both ends of a string.
- Undo/Redo Functionality: Deques can store states for undo and redo operations in text editors.
- Task Scheduling: Deques can be used to manage tasks that may need reordering or prioritization from both ends.
Important: Queue can be Double-Ended Circular Queue which supports circular behavior with insertion and deletion from both ends. Characteristics:
|