Double-Ended Queues
Compare insertion and removal at both the front and the back.
Core Intuition & How It Works
A double-ended queue (deque) supports O(1) insertion and removal at both the front and the back. It generalizes both stacks and queues in one structure and powers 0-1 BFS and monotonic queues.
In the Byte Sized Algorithms interactive classroom, you can step forward and backward through this algorithm with your keyboard while watching the visual diagram, memory state, and highlighted pseudocode update together.
Time & Space Complexity
| Metric | Complexity |
|---|---|
| Time Complexity | O(1) front/back push and pop |
| Space Complexity | O(n) |
| Topic Chapter | Chapter 5: Stacks & Queues |
| Difficulty Level | Intermediate |
Key Pattern to Recognize
Reach for a deque when elements expire from the front by age while inferior candidates are discarded from the back.
Common Pitfalls & Edge Cases
Popping from the wrong end and accidentally turning a FIFO queue into a LIFO stack.
Real-World & Technical Interview Applications
Sliding-window maximum, work-stealing thread schedulers, palindrome checkers, and 0-1 BFS shortest paths.