ArticleslgStudy

computer science

Pairing heap

Pairing heap is a computer 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 Pairing heap rather than just read about it. In short: A pairing heap is a type of heap data structure with relatively simple implementation and excellent practical amortized performance, introduced by Michael Fredman, Robert Sedgewick, Daniel Sleator, and Robert Tarjan in 1986. Pairing heaps are heap-ordered multiway tree structures, and can be considered simplified Fibonacci heaps.

Key takeaways

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

Reference excerpt

A pairing heap is a type of heap data structure with relatively simple implementation and excellent practical amortized performance, introduced by Michael Fredman, Robert Sedgewick, Daniel Sleator, and Robert Tarjan in 1986. Pairing heaps are heap-ordered multiway tree structures, and can be considered simplified Fibonacci heaps. They are considered a "robust choice" for implementing such algorithms as Prim's MST algorithm, and support the following operations (assuming a min-heap):

find-min: simply return the top element of the heap. meld: compare the two root elements, the smaller remains the root of the result, the larger element and its subtree is appended as a child of this root. insert: create a new heap for the inserted element and meld into the original heap. decrease-key (optional): remove the subtree rooted at the key to be decreased, replace the key with a smaller key, then meld the result back into the heap. delete-min: remove the root and do repeated melds of its subtrees until one tree remains. Various merging strategies are employed. The analysis of pairing heaps' time complexity was initially inspired by that of splay trees. The amortized time per delete-min is O(log n), and the operations find-min, meld, and insert run in O(1) time. When a decrease-key operation is added as well, determining the precise asymptotic running time of pairing heaps has turned out to be difficult. Initially, the time complexity of this operation was conjectured on empirical grounds to be O(1), but Fredman proved that the amortized time per decrease-key is at least Ω ( log ⁡ log ⁡ n ) {\displaystyle \Omega (\log \log n)} for some sequences of operations. Using a different amortization argument, Pettie then proved that insert, meld, and decrease-key all run in O ( 2 2 log ⁡ log ⁡ n ) {\displaystyle O(2^{2{\sqrt {\log \log n}}})} amortized time, which is o ( log ⁡ n ) {\displaystyle o(\log n)} . Elmasry later introduced elaborations of pairing heaps (lazy, consolidate) for which decrease-key runs in O ( log ⁡ log ⁡ n ) {\displaystyle O(\log \log n)} amortized time and other operations have optimal amortized bounds, but no tight Θ ( log ⁡ log ⁡ n ) {\displaystyle \Theta (\log \log n)} bound is known for the original data structure. Although the asymptotic performance of pairing heaps is worse than other priority queue algorithms such as Fibonacci heaps, which perform decrease-key in O ( 1 ) {\displaystyle O(1)} amortized time, the performance in practice is excellent. Jones and Larkin, Sen, and Tarjan conducted experiments on pairing heaps and other heap data structures. They concluded that d-ary heaps such as binary heaps are faster than all other heap implementations when the decrease-key operation is not needed (and hence there is no need to externally track the location of nodes in the heap), but that when decrease-key is needed pairing heaps are often faster than d-ary heaps and almost always faster than other pointer-based heaps, including data structures like Fibonacci heaps that are theoretically more efficient. Chen et al. examined priority queues specifically for use with Dijkstra's algorithm and concluded that in normal cases using a d-ary heap without decrease-key (instead duplicating nodes on the heap and ignoring redundant instances) resulted in better performance, despite the inferior theoretical performance guarantees.

Structure A pairing heap is either an empty heap, or a pairing tree consisting of a root element and a possibly empty list of pairing trees. The heap ordering property requires that parent of any node is no greater than the node itself. The following description assumes a purely functional heap that does not support the decrease-key operation.

type PairingTree[Elem] = Heap(elem: Elem, subheaps: List[PairingTree[Elem]]) type PairingHeap[Elem] = Empty | PairingTree[Elem]

A pointer-based implementation for RAM machines, supporting decrease-key, can be achieved using three pointers per node, by representing the children of a node by a doubly-linked list: a pointer to the node's first child, one to its next sibling, and one to its previous sibling (or, for the leftmost sibling, to its parent). It can also be viewed as a variant of a Left-child right-sibling binary tree with an additional pointer to a node's parent (which represents its previous sibling or actual parent for the leftmost sibling). Alternatively, the previous-pointer can be omitted by letting the last child point back to the parent, if a single Boolean flag is added to indicate "end of list". This achieves a more compact structure at the expense of a constant overhead factor per operation.

Operations

Meld Melding with an empty heap returns the other heap, otherwise a new heap is returned that has the minimum of the two root elements as its root element and just adds the heap with the larger root to the list of subheaps:

function meld(heap1, heap2: PairingHeap[Elem]) -> PairingHeap[Elem] if heap1 is Empty return heap2 elsif heap2 is Empty return heap1 elsif heap1.elem < heap2.elem return Heap(heap1.elem, heap2 :: heap1.subheaps) else return Heap(heap2.elem, heap1 :: heap2.subheaps)

Insert The easiest way to insert an element into a heap is to meld the heap with a new heap containing just this element and an empty list of subheaps:

function insert(elem: Elem, heap: PairingHeap[Elem]) -> PairingHeap[Elem] return meld(Heap(elem, []), heap)

Find-min The function find-min simply returns the root element of the heap:

function find-min(heap: PairingHeap[Elem]) -> Elem if heap is Empty error else return heap.elem

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Pairing heap

Start with the simplest possible case. Write down what Pairing heap claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer 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 Pairing heap 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 Pairing heap 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 Pairing heap

In research
Pairing heap appears in computer 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 Pairing heap 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
Pairing heap is common in secondary-school and first-year university syllabi. It links to neighbouring topics Amortized data structures, Heaps (data structures), so understanding it makes those chapters shorter.
In everyday life
Look for Pairing heap 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.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Pairing heap in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Pairing heap 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 Pairing heap out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Pairing heap in simple terms?

A pairing heap is a type of heap data structure with relatively simple implementation and excellent practical amortized performance, introduced by Michael Fredman, Robert Sedgewick, Daniel Sleator, and Robert Tarjan in 1986. Pairing heaps are heap-ordered multiway tree structures, and can be consid…

Why does Pairing heap matter?

Because it connects several computer 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 Pairing heap?

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 Pairing heap.

Tags

  • Amortized data structures
  • Heaps (data structures)

Keep exploring