Back to Academy
stacks queues
Deque
A Deque (Double-Ended Queue) is a linear data structure that allows insertion and removal of elements from both the front and the rear. It generalizes both stacks and queues, supporting LIFO and FIFO operations simultaneously. It is useful when you need efficient operations on both ends of a collection.
Use Cases
- •Sliding window maximum/minimum problems
- •Implementing undo/redo with bounded history
- •Work-stealing algorithms in parallel computing
Complexity Analysis
| Metric | Best | Average | Worst |
|---|---|---|---|
| Time | O(1) | O(1) | O(1) |
| Space | O(n) | ||
Visualization
frontrear
Implementation
Output
Click "Run Code" to see output...