Codacoda
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

MetricBestAverageWorst
TimeO(1)O(1)O(1)
SpaceO(n)

Visualization

frontrear
Speed:1x
Empty queueStep 1 / 9

Implementation

Output

Click "Run Code" to see output...