A Deque (Double-Ended Queue) allows insertions and deletions at both the front and rear endpoints.
pushBack(20) puts 20 at tail. pushFront(10) puts 10 at head.
Deque State: [10 (Head), 20 (Tail)]popBack() removes and returns item from tail (20).
Popped: 20 | Deque State: [10 (Head & Tail)]Passengers can enter or exit from either the front engine car or the rear caboose car.
1 step (Constant)
O(1) Constant Time
O(N) Auxiliary Space
Memory growth rate as N expands.
Relative efficiency rating for large N.
| Operation | Time Complexity | Space Complexity |
|---|---|---|
| Push Front / Back | O(1) | O(1) |
| Pop Front / Back | O(1) | O(1) |
const deque = [];
deque.unshift(10); // push front
deque.push(20); // push back
const front = deque.shift(); // pop frontMonotonic queue pattern algorithms.
Bidirectional history managers.
Validate your conceptual understanding, operation mechanics, and core concepts of Deque.
Use Deques when an algorithm requires flexible push and pop capabilities at both boundaries simultaneously!
Double-Ended Queue (Deque) ready. Operations allowed on both ends.