Pairing heaps: the forward variant

Dani Dorfman, Haim Kaplan, László Kozma, Uri Zwick

TL;DR

This paper provides the first theoretical breakthrough in over thirty years on the forward variant of pairing heaps, proving that insert and delete-min take $O(\log n \cdot 4^{\sqrt{\log n}})$ amortized time. By introducing a novel potential function that directly tracks rank-differences between parents and children rather than relying on splay-tree analogies, the authors smash the long-standing $O(\sqrt{n})$ upper bound down to a sub-polynomial rate.

What Problem Does This Paper Address?

Pairing heaps, introduced by Fredman et al. in 1986, are self-adjusting priority queues famous for their simplicity and exceptional empirical performance. In the standard pairing heap, deleting the minimum key triggers two consolidation passes over the root's children:

  1. A left-to-right pairing round linking adjacent siblings.
  2. A right-to-left accumulation round folding the resulting trees into one.

Fredman et al. also proposed the forward variant (or front-to-back variant), which runs both rounds from left to right. This variant is arguably more intuitive and easier to implement with standard singly-linked child/sibling pointers. However, while the standard pairing heap maps cleanly to splay trees (granting an $O(\log n)$ amortized bound), the forward variant's accumulation round repeatedly reverses the order of sibling blocks. In the binary tree representation, this turns long segments of search paths upside-down, causing classical splay-tree analyses to break down completely. As a result, the forward variant remained stuck with a coarse $O(\sqrt{n})$ amortized bound for over three decades.

Methods

The authors abandon splay-based subtree-size potentials and instead measure tree quality via key-rank differences:

  • Rank Differences and Categories: The rank $r(x)$ of an item is defined as the number of smaller items in the heap, and its rank-difference is $rd(x) = r(x) - r(p(x))$ relative to its parent $p(x)$. Nodes are grouped into $t$ logarithmic categories based on the scale of their rank-differences using a geometric scaling parameter $q$.
  • Two-Part Potential Function:
  • Node Potential ($\Phi_N$): Scaled rank-differences such that linking two nodes of the same category guarantees a decrease of at least 1 in potential.
  • Box Potential ($\Phi_B$): To amortize "unproductive" links across rounds and operations, contiguous groups of siblings are grouped into analytical "boxes" of size $2^b - 1$. As boxes shrink or dissolve during pairing, they release stored potential to pay for linking steps.
  • Epoch-Based Lookahead for Insertions: To prevent newly inserted keys from perturbing the ranks of existing elements and invalidating box invariants, the analysis divides operations into epochs. Ranks are determined with respect to all keys that will appear in the heap throughout that epoch, fixing rank assignments over blocks of $\Omega(n)$ operations.

Datasets

Not discussed in the paper.

Key Insights and Ideas

  • Direct Order-Based Potential: Self-adjusting heaps are fundamentally performing partial selection sorting. Analyzing them via structural tree sizes (the splay tree approach) is an awkward proxy; directly quantifying how far a node is from its parent in the sorted key order is far more robust against restructuring anomalies.
  • The "Good Link" Counting Argument: A linking step is defined as "good" if it links two nodes of the identical category, or if it replaces the running prefix minimum during accumulation. The authors prove that at least one good link occurs for every $t \cdot 2^t$ links, bounding the total uncharged work.
  • Asymmetry of Linking: Pairing heaps link by placing the larger key as the leftmost child of the smaller key. The authors observe that if heaps instead linked to the rightmost position, the forward variant would become trivial to analyze and the standard variant would become notoriously difficult.

Key Results

  • Sub-Polynomial Amortized Bounds: For sequences of arbitrary insert and delete-min operations starting from an empty heap, both operations run in amortized time: $$\mathcal{O}\left(\log n \cdot 4^{\sqrt{\log n}}\right)$$ where $n$ is the number of elements.

  • Asymptotic Improvement: Because $4^{\sqrt{\log n}} = o(n^\varepsilon)$ for every $\varepsilon > 0$, this bounds the cost to asymptotically smaller than any polynomial, greatly improving upon the 1986 $O(\sqrt{n})$ bound.

  • Meld Support: The same amortized bound of $O(\log n \cdot 4^{\sqrt{\log n}})$ directly extends to the meld operation.

Limitations and Future Work

  • Not Logarithmic Yet: While sub-polynomial, the bound is strictly super-logarithmic ($c^{\sqrt{\log n}} = \omega(\log^d n)$ for any $c, d > 1$). Proving or disproving whether the forward variant achieves true $O(\log n)$ amortized time remains an open question.
  • Decrease-Key Unresolved: The paper does not analyze the decrease-key operation. While Fredman's $\Omega(\log \log n)$ lower bound applies, it remains unknown whether decrease-key can be supported in $o(\log n)$ time in this variant.
  • Constant Factors and Practice: The combinatorial tracking structures (boxes and scaling constants) introduce large constants in the upper bound. Empirical observations still show the forward variant to be somewhat slower in practice than the standard variant.

Summary updated

BibTeX
@inproceedings{dorfman2018pairing,
  author = {Dani Dorfman and Haim Kaplan and László Kozma and Uri Zwick},
  title = {{Pairing heaps: the forward variant}},
  booktitle = {MFCS},
  year = {2018},
  url = {https://openreview.net/forum?id=8t5mwAoaNr9},
}
Figure