ArticleslgStudy

science

Double-ended queue

Double-ended queue is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Double-ended queue rather than just read about it. In short: In computer science, a double-ended queue (abbreviated as deque — DEK), is an abstract data type that serves as a container, with a restricted access to the stored items. As a generalization of both the stack and the queue, the deque may have similar functions as a data buffer: it can be use both as a retainer (queue), or for backtracking (stack).

Double-ended queue — main illustration
Double-ended queue — illustration

Key takeaways

  • Double-ended queue belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Double-ended queue to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Double-ended queue from memory before moving on to harder problems.

Reference excerpt

In computer science, a double-ended queue (abbreviated as deque — DEK), is an abstract data type that serves as a container, with a restricted access to the stored items. As a generalization of both the stack and the queue, the deque may have similar functions as a data buffer: it can be use both as a retainer (queue), or for backtracking (stack). However it offers greater flexibility in managing the order of elements and some algorithms are based on its functionalities.

Description The double-ended queue is most often presented as a generalized queue, which gives its name. It is a queue that "allows insertions and deletions at both ends". The deque is also described as a generalization of the stack abstract data structure, as "two stacks joined together at the base", with a shared bottom item, or as a combination of both the stack and the queue.

And then conversely the queue and the stack are restricted forms of the deque.

Different analogies with real-world objects are used to describe the deque. It is compared to a "deck of cards" with which the structure shares some properties and the pronunciation. The deque is also likened to a "necklace with beads that can be added and/or removed at either end". Like the queue, it is depicted as a set of items lined up in a pipe open at both ends ; unlike the queue, the items can move in both direction in the pipe. The "railroad model" introduced by Knuth (after "Dijkstra's shunting yard") focus on the similarity with the queue, with one input and one output, and switches to select the side of the deque to be accessed. The main operations on a deque are said to act on either side (or end) of the structure: addition of an item into the collection (enqueue), removal of an item (dequeue), and reading of an item (peek). At a given point in time only two items can be accessed, from either side of the deque, based on the history of the structure. The designated item on one side is either the latest one that has been inserted on this side (LIFO behavior), or, — if there is none —, the oldest one that has been inserted on the other side (FIFO behavior). This service policy gives the structure more flexibility and versatility, but it is also more difficult to fathom and use. The six main operations on a deque may be described in two ways, based on the queue (or stack) operations: either by duplicating them, on each end of the structure (add_left, add_right, etc.), or by generalizing them with a parameter that indicates the location on which an operation is performed (add(left,...), add(right,...), etc.). Each approach has its merits: the first one allows the overloading of the operations but needs to have different names on each sides, while the second one simplifies the interface by halving the number of operations and allows to make use of the symmetry of the structure. In what follows, we will go with the second option to avoid needless repetition. The deque has two other possible sub-types (more restricted forms are useless) :

An input-restricted deque is one where deletion can be made from either end, but insertion can be made at one end only. It is a queue with a back output, or a stack with a bottom output. An output-restricted deque is one where insertion can be made at either end, but deletion can be made from one end only. It is a queue with a front input, or a stack with bottom input. Despite their limitations these sub-types have many applications and some of their implementations may be simpler.

After Knuth, these structures are often described as different forms of restricted linear lists , or sequences. They maintain the contained elements in a given order while only allow access to some of them: the first one and/or the last one in the sequence. However other authors object that they "hide their internal dynamism from the user" and only the common implementations are linear. They consider these restricted-access data structures are either:

semi-structured: they have "a special or designated item but no logical relationship among the rest of the items", and "the operation that deletes an item takes no item as a parameter"; or point structures "because only two points of a queue exist for the outside world": the stack is then a one-point structure, while the queue and the deque are two-point structures. For example, a deque can be implemented with a min-max heap, or with a set: before an item is inserted, it is tagged with a integer used as its value in the heap, and that depends on the history of the container. The stored elements in a heap are not ordered and their locations depend on the internal state of the structure. Another common restricted access structure is the priority queue, which is not a linear structure. The deque can be generalized by the addition of some operations: a deque with heap order, or mindeque, allows the find-min operation. Fast or even optimal catenation is also possible. Some authors consider the deque structure as being of little use, less useful than its restricted forms, especially the stack and the queue.

Specification The deque is here considered as unbounded: it can contain an unlimited (and undefined) number of items. A bounded deque is possible, and requires a slightly different specification, but when an overflow occurs the behavior depends on the implementation: error value, exception, deletion, etc. Let a deque d ∈ D, an item x ∈ X, and a side (end) e ∈ E = {left,right} with ¬ left = right Key operations: with D* = D \ {Λ}

As a linear structure, the deque can be specified in terms of catenation (noted "~") of sequences and singleton sequences (noted "< ... >").

An axiomatic specification (or algebraic) of the deque can be obtained by extending and merging those of the stack and the queue. (see Nguyen thesis for an alternative formulation). Axiomatic constraints:

The sequence of operations in the previous example results in the following expression: d = remove( right, add(left, DE, remove( left, remove( left, add(right, UE, add(right, QUE, add(left, STA, remove(left, add(right, CK, add(left,DE,Λ) ))))))))) This can be simplified with the axioms (1), (2) and (3). In order of application, from the empty deque :

This results in the following expression:

d = add(left,DE,add(right,QUE,Λ)) As a transformation from an empty sequence :

< > add(right,QUE)⟼ < QUE > add(left,DE)⟼ < DE,QUE > Conversely the stack and the queue can be specified axiomatically in terms of the deque.

… excerpt ends here. Continue reading the full article.

Illustrations

Double-ended queue illustration
Double-ended queue: Railroad model of a deque
Railroad model of a deque
Double-ended queue: Several values are inserted at the end of a dynamic array using geometric expansion. Grey cells indicate space reserved for expansion. Most insertions are fast (constant time), while some are slow due to the need for reallocation (Θ(n) time, labelled with turtles).
Several values are inserted at the end of a dynamic array using geometric expansion. Grey cells indicate space reserved for expansion. Most insertions are fast (constant time), while some are slow due to the need for reallocation (Θ(n) time, labelled with turtles).
Double-ended queue: UML class diagram of a double-ended queue
UML class diagram of a double-ended queue

Worked examples

Example 1 — a first encounter with Double-ended queue

Start with the simplest possible case. Write down what Double-ended queue claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Double-ended queue before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Double-ended queue ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Double-ended queue

In research
Double-ended queue appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Double-ended queue in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Double-ended queue is common in secondary-school and first-year university syllabi. It links to neighbouring topics Abstract data types, so understanding it makes those chapters shorter.
In everyday life
Look for Double-ended queue outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Double-ended queue” →

How to study Double-ended queue in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Double-ended queue means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Double-ended queue out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Double-ended queue in simple terms?

In computer science, a double-ended queue (abbreviated as deque — DEK), is an abstract data type that serves as a container, with a restricted access to the stored items. As a generalization of both the stack and the queue, the deque may have similar functions as a data buffer: it can be use both a…

Why does Double-ended queue matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Double-ended queue?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Double-ended queue.

Tags

  • Abstract data types

Keep exploring