Resource · Guide or article
Deque (Double-Ended Queue)
Reference page for the double-ended queue, which allows constant-time adds and removes at both ends and can serve as either a stack or a queue.
Reviewed
Open the original: Deque (Double-Ended Queue) (opens the original site in a new tab)Add to a roadmap
Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.
Source content: English
A deque (pronounced "deck", short for double-ended queue) is a linear data structure that generalizes both a stack and a queue. Elements can be added or removed from either end — the front (head) or the back (tail) — in O(1) time. A deque is the right tool when you need O(1) access at both ends: This implementation is backed by the project's existing DoublyLinkedList. Because every node keeps a reference to both its previous and next neighbours, this gives O(1) prepend (for addFront), O(1) deleteHead (for removeFront) and O(1) append / deleteTail (for addBack / removeBack), with no need to shift array elements. The number of elements is tracked in a counter, so size is O(1) too.
PrepKit overview
PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.
- Suited to
- The source does not state a level
- Format
- Reference
What it covers
- Table of eight operations, from addFront to size, each O(1), with O(n) space
- Explains that size stays O(1) because of a running counter
- Use cases including monotonic-deque sliding window max and min, undo and redo, and work-stealing schedulers
- Implementation note: built on the repository's DoublyLinkedList, with a circular buffer mentioned as the alternative
How to use it
PrepKit study advice, not a claim made by the source.
Use a deque to solve sliding window maximum, then explain aloud why each element is pushed and popped at most once.
Scope and limitations
Describes the API rather than teaching an algorithm, and has no worked sliding-window example. The implementation note depends on the repository's own linked list.
Access and format
README on GitHub in trekhleb/javascript-algorithms (MIT). English, free to read.
Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88
Evidence behind this overview
- src/data-structures/deque/README.md
Pages that include this
Get the PrepKit newsletter
Optional. You don't need it to use PrepKit.