Towards a Final Analysis of Pairing Heaps

Seth Pettie£ Max Planck Institut f¨ur Informatik

Abstract perimentally that the cost of decreasekey is virtually, if not asymptotically, constant, and Moret & Shapiro [10] con- Fredman, Sedgewick, Sleator, and Tarjan proposed the cluded that in Prim’s minimum spanning algorithm pairing as a self-adjusting, streamlined version of the pairing heaps are faster than the alternatives. These in- . It provably supports all cluded binary heaps, splay heaps, Fibonacci heaps, and oth- operations in logarithmic time and is known to be extremely ers. The pairing heap is now included in implementations efficient in practice. However, despite its simplicity and of the GNU C++ library and the LEDA library [9]. empirical superiority, the pairing heap is one of the few Fredman [4] proved the remarkable result that on a spe- popular data structures whose basic complexity remains cific distribution of operation sequences, no (generalized)

open. In this paper we prove that pairing heaps support pairing heap can perform optimally. Specifically, there

Ò Ò ÐÓ Ò

the deletemin operation in optimal logarithmic time and are sequences of Ò insertions, deletions, and de-

Ò ÐÓ Ò ÐÓ ÐÓ Òµ

all other operations (insert, meld, and decreasekey) in time ª´

Ô creasekeys that take time to execute.

¾ ÐÓ ÐÓ Ò

Ç ´¾

µ. This result gives the first sub-logarithmic He concluded that the complexity of the decreasekey op-

Òµ Ç ´ÐÓ Òµ

time bound for decreasekey and comes close to the lower eration lies somewhere between ª´ÐÓ ÐÓ and .

Òµ bound of ª´ÐÓ ÐÓ established by Fredman. The difference between optimality and suboptimality is not as stark as one might think. Because the user of Pairing heaps have a well known but poorly understood re- a priority queue has already resigned himself to paying

lationship to splay trees and, to date, the transfer of ideas

Ò ÐÓ Òµ Ò ¢´ time for deletemins, a non-constant cost for has flowed in one direction: from splaying to pairing. One decreasekey will only be detectable for sufficiently dense contribution of this paper is a new analysis that reasons ex- input sequences. (Density is the ratio of decreasekeys plicitly with information-theoretic measures. Whether these to deletemins.) For example, if Fredman’s lower bound ideas could contribute to the analysis of splay trees is an turns out to be tight, this would imply that in the stan- open question. dard graph applications (shortest paths, weighted match- ings, minimum spanning trees, etc.) pairing heaps are no

worse than Fibonacci heaps when the number of edges is

´Ò ÐÓ Ò ÐÓ ÐÓ Òµ 1 Introduction Ç . Fredman’s lower bound only estab-

lishes that the pairing heap is suboptimal in the density

´ÐÓ Ò ÐÓ ÐÓ Òµ Ó´ÐÓ Ò ÐÓ ÐÓ Òµ Twenty years ago Fredman et al. [5] proposed the pair- range  to ; for other ing heap, a simple priority queue that they ranges its complexity remains open. conjectured to be as efficient as Fibonacci heaps [6]. In In this paper we provide the first proof that pairing heaps their original analysis Fredman et al. proved that all priority support decreasekeys in sub-logarithmic time.

queue operations (insert, deletemin, meld, and decreasekey)

´ÐÓ Òµ Ò were supported in Ç amortized time, where is the Theorem 1 The pairing heap executes a mixed sequence

size of the heap. Although logarithmic time is optimal for Ò of Ñ priority queue operations, including deletemins, in

deletemin, theoretically efficient priority queues like the Fi- Ô

¾ ÐÓ ÐÓ Ò

Ç ´Ò ÐÓ Ò · Ѿ

µ time. ´½µ bonacci heap enjoy Ç amortized time for insert, meld,

and decreasekey.

Ô

¾ ÐÓ ÐÓ Ò

In the intervening years pairing heaps have become the The ¾ function lies in the asymptotic spectrum

¯

´ ´ÐÓ ÐÓ Òµµ Ó´ÐÓ Òµ priority queue of choice in applications requiring the de- between  poly and . It is an ugly creasekey operation. Stasko & Vitter [8] demonstrated ex- bound and undoubtedly not tight. Nonetheless, we can now

£ claim with certainty that the pairing heap is asymptotically

Supported by an Alexander von Humboldt Postdoctoral Fellowship. Ô

¾ ÐÓ ÐÓ Ò

Ç ´ÐÓ Ò¾ Email: [email protected]. optimal for any density µ. The Pairing Heap. The structure consists of a single rectly. rooted tree where the children of a node are assigned some left-to-right ordering. Each node is identified with a key and Overview. In Section 2 we discuss the original analysis of the key of a parent is no larger than the key of any child. (It pairing heaps in order to provide a reference point for our is heap ordered.) During the execution of an operation there

approach. In Section 3 we introduce some key ideas and, as

Ô

Ü Ü ¾

may be multiple rooted trees. If ½ are two roots then

´ ÐÓ Òµ

a warmup, sketch a proof that decreasekeys take Ç

Ü Ü Ü Ü

¾ ½ ¾ linking ½ and either makes the leftmost child of or time. The full proof of Theorem 1 appears in Section 4. vice versa, depending on which node’s key is smaller. The In Section 5 we discuss some open problems and make a operations are implemented as follows. An insert creates conjecture on the actual complexity of pairing heaps. a new node with a given key and links it with the existing root. A meld of two given heaps simply links their roots. A decreasekey operation is given both a node and the heap to 2 Pairing Heaps, Entropy, and Potentials which it belongs. It detaches the subtree rooted at the given node, reduces the node’s key appropriately, then links the The original analysis of pairing heaps [5] was a stroke of given node with the existing heap root. elegance. However, it was achieved by drawing a slightly By the heap-order property the minimum node is neces- unnatural correspondence between pairing heaps and splay sarily at the root. A deletemin proceeds by detaching ev- trees. In particular, Fredman et al. [5] map a general rooted ery child of the root then linking children in a prescribed tree to a : a node’s left child in the binary rep- fashion until one tree remains. Several linking strategies resentation corresponds to its leftmost child in the general

have been proposed [5, 8, 3]. In this paper we consider the tree and its right child corresponds to its right sibling in the

Ü Ü  Ü

¾  standard 2-pass version given in [5]. Let ½ be general tree. They observe that in the binary representation

the children of the root in left-to-right order. In the cou- a deletemin operation looks very similar to a splay up the

´Ü Ü µ ´Ü Ü µ ´Ü Ü µ

¾ ¿   

pling pass we link the pairs ½ . right shoulder of the tree. By borrowing the same poten-

Ý Ý  Ý

¾ 

Let ½ be the winners of these linkings, where tial function and analysis from [11] they derive amortized

Ý Ü Ý

 

 if is odd. In the accumulation pass we link logarithmic bounds on deletemins and all other operations.

Ý Ý

½  ¾

with  , the winner of this comparison with ,andso

Ý Ý  Ý

·½  on; in general,  is linked with the winner of .

Previous Work. Fredmanetal.[5]provedthatthe

´ÐÓ Òµ 2-pass version of deletemin takes Ç amortized time. They also considered arbitrary coupling, multi-

pass,andbackward 2-pass.1 It was shown that arbi-

Ô

Òµ

trary coupling takes ¢´ time and that multipass takes

Ô

´ÐÓ Ò ÐÓ ÐÓ Ò ÐÓ ÐÓ ÐÓ Òµ Ó´ Òµ Ç time. No time bound is known for backward 2-pass. Stasko and Vitter [8] Figure 1. The general trees are marked with and Elmasry [2] proposed several variants of these linking circular nodes, the binary representation with strategies. In [8] it was observed that with a small inser- square nodes. On the left is a tree with en-

tion buffer the amortized cost of insertion can be reduced tropy zero and on the right is a tree with en-

´½µ ÐÓ´ µ

to Ç . Iacono [7] proved that even the standard 2-pass tropy . ´½µ

version supports insert and meld in Ç time. Bringing the ´½µ

insertion cost to Ç is significant in applications where

the heap is likely to end in a non-empty state, for instance, The analysis of [5] uses the potential function ¨

È

״ܵ ״ܵ

when computing single-source, single-destination shortest ÐÓ where is the size of the subtree rooted Ü

paths with Dijkstra’s algorithm. Iacono [7] and Elmasry at Ü in the binary representation. One property of this func- [2] studied the distribution-sensitive properties of pairing tion is that general trees with completely different charac- heaps. Before the pairing heap was introduced Sleator and teristics can get assigned the same potential. In Figure 1 Tarjan [12] invented the skew-heap, a self-adjusting data we have, among rooted 5-node trees, the two with mini- structure that supported insert, deletemin, and meld in log- mum and maximum entropy, respectively. Here entropy is arithmic time; however, it did not support decreasekeys di- the logarithm of the number of linear extentions consistent with the heap-order. Since both trees get assigned a poten- 1Arbitrary coupling partitions the roots into couplets arbitrarily and ac-

tial of ÐÓ´ µ one wonders if there is an interpretation of cumulates the couplet winners in no specific order. Multipass repeatedly

executes the coupling pass of 2-pass and backward 2-pass accumulates the this potential that makes sense in the context of a priority

Ý    Ý ½ roots from left-to-right rather than right-to-left. queue. Let us examine the effect of one comparison on ¨. Sup- somewhat unintelligent fashion a deletemin operation can

pose that a tree rooted at Þ is linked as the leftmost child of fail to reduce entropy by more than a negligible amount. In

Ý Þ  Ý , with and having and nodes in their trees, respec- order to bound the amortized complexity of such an opera- tively. See Figure 2. tion we must show that it nevertheless made some kind of

measurable progress. Consider a singleton node Ü with no

children. If, before the deletemin, its parent’s subtree had

Þ Ý

Þ Ý

Ô¾ ´Üµ size Ô and afterward it has size , the difference in

(information) is miniscule for Ô large. On the other hand,

if this trend continues then Ü will only have to endure an-

 

´ÐÓ Ôµ other Ç inefficient linkings before an efficient one.

In short, by the measure of anti-information, Ü has made

Ý one “anti-bit” of progress.

Þ Ý Þ The intuition above can be recast in several ways. One way, advocated by Fredman [4] in his lower bound proof, is to view a pairing heap as searching for the rank of every node, where rank is the logarithm of the size of its subtree.

An efficient link is one between nodes with ranks differ-

 ½ ½  ½ ½ ing by at most a constant. (A high-rank node becoming the child of a low-rank node is also efficient but this should happen infrequently.) Although ranks change over time it Figure 2. The effect of one linking. Circular is useful to think of them as essentially fixed. The kernel

nodes correspond to the general representa- of Fredman’s lower bound is the observation that after a de- Ü

tion and square ones to the binary represen- creasekey on Ü, nothing is “known” about the rank of ex-

 ÐÓ Ò tation. cept that it lies in the range ¼ . The pairing heap, in- capable of revealing more than one bit of information about

a node’s rank in every comparison, must engage Ü in at least

A quick calculation shows that regardless of the out-

Òµ ª´ÐÓ ÐÓ comparisons on the average before its first ef-

come of the comparison the increase in potential ¨ is 

 ficient linking. That is, no linking policy can do better than

´· µ´· ½µ

½

ÐÓ . Ignoring the pesky “ ”, this in- a binary search. On the upper bound side, the analysis of 

[5] says that pairing heaps do at least as well as a linear

´Þ µ·´Þ µ crease can be decomposed into  :

search. (The term search here is only meant to evoke a fa-

¡ ¡

· ·

´Þ µ ÐÓ ´Þ µ ÐÓ

 miliar concept; pairing heaps do not search for anything.) 

 In this language, Section 3 gives a proof that pairing heaps

´Þ µ

where  represents the entropy reduction (bits of infor- do at least as well as a two-stage linear search. This leads

Ô

´Þ ݵ ´Þ µ

´ ÐÓ Òµ

mation) of the link and is, for lack of a bet- to a Ç upper bound on decreasekeys. In Section 4

Þ ݵ ter term, the anti-information of link ´ . That is, anti- we generalize this idea to a kind of multi-stage search.

information measures the hypothetical entropy reduction if Þ the comparison between Ý and had the opposite outcome. 3 Introduction to the Analysis The roles of information and anti-information are not sym- metric. As we will see in Sections 3 and 4, anti-information At any moment the links of a pairing heap can be parti- is a critical measure. Although not stated explicitly, the tioned into three categories: those destined to be cut by a de- role of information in the original analysis [5] is to keep the creasekey operation, those destined to be cut by a deletemin, proofs simple: with a symmetric potential function one can and those not cut at all. We call the first type illusory and afford to be oblivious to the outcomes of individual com- the rest normal. The size of the subtree rooted at Ü is an parisons. It is possible to reprove the results of [5] using

È important statistic, but an unstable one since nodes that lie

¼

´Üµ the alternative potential ¨ . Lemma 2 is an Ü below an illusory edge will, at some point in the future, be

interesting exercise.

Ü

moved out of Ü’s subtree. Let be the size of the nor-

Ü Ü

mal subtree rooted at Ü. Clearly, until is deleted is ¼

Lemma 2 An insert, decreasekey, or meld increases ¨ by

´Üµ Ü

non-decreasing over time. Let Ô be the parent of and

´ÐÓ Òµ

Ç . If the root has children then performing a

Դܵ

 be w.r.t. the moment just before establishing the link

¼

Ç ´ÐÓ Òµ

deletemin reduces ¨ by .

Ü Դܵµ ´Üµ 

´ . We redefine w.r.t. the measure:

 

¼

¨

Ü · Դܵ

There is an intuitive argument for why is a sensible 

´Üµ ÐÓ

potential function. Because the pairing heap behaves in a

Ü

´Üµ ¼ and if Ü is a root, by definition. We illustrate just two sub-cases of this analysis, in or- Recall that the deletemin operation consists of two der to exhibit the important features of our approach. passes: a coupling pass and an accumulation pass. Two An exhaustive case analysis is pointless since these re- nodes form a couplet if, in their next linking, they are des- sults are superceded by those in Section 4.

tined to be linked in the coupling pass of a deletemin. Ev-

Ü Ü

·½ Case 1. Suppose that  form a closed cou-

ery node is either open or closed. A closed-couplet is one ¼

Ü Ü Ü

·½  plet, and that  loses to ,whichlosesto .We

in which both nodes are closed. The overall potential of the

´´ ·  ·  µ µ charge ¾ ÐÓ units of potential to the heap is: deletemin operation, which we account for later. As-

¼¼ suming that neither of the new edges is illusory, the

´ µ ¨ # of closed-couplets

 reduction in potential is:

Ü ´Üµ

if is closed



· ·  · ·

·

·ÐÓ ÐÓ ÐÓ

Ô

  

´Üµ

Ô

Ü

· ÐÓ Ò Ü

if is open ¼

· ·  · ·

ÐÓ Ò

· ¾ ÐÓ ½ ÐÓ

 · 

   

¾ ¾

´· µ · µ´· · µ

As a rule, every node begins life in an open state. Since ´

 ÐÓ  ½  ÐÓ

¾

¾ ¾

´Üµ  ÐÓ Ò Ü

the potential contributed by is no more than

Ô Ô

ÐÓ Ò Ü ´Üµ ÐÓ Ò

¾ .If is open and drops below we ½ close it, which, one sees by inspection, can only cause a where the “ ” in the second line accounts for the loss

reduction in potential. of a closed couplet. The potential reduction is used to ´½µ pay for Ç comparisons, including those involving

Decreasekey. Let Ü be the node in question. The link

Ü Ü

·½

 but possibly some others.

Ü Դܵµ

´ must be cut, and is by definition illusory.

Ü Ü

·½ Case 2. Suppose that  are both open, and

Since the nodes in Ü’s subtree do not contribute to the

¼

Ü Ü Ü

·½ 

again, that  loses to ,whichlosesto .We

Դܵ size (by the  measure) of ancestors above ,cut- borrow nothing from the deletemin operation; the re- ting this link does not affect the function or the over-

¼ duction in potential is: Ü

all potential of the tree. We link Ü with the root; let

Ô

¼

´Ü µ  ÐÓ Ò

be the loser of this comparison. If we

¼ ¼

´Ü µ

designate Ü closed, increasing the potential by .

½

¼ ¼

· · ·  ·

Ü ´Ü µ ÐÓ Ò

Ô

ÐÓ ÐÓ

Otherwise is open. Since is bounded by ·ÐÓ

Ô

  

ÐÓ Ò

ÐÓ Ò

the increase in potential is at most ¾ .



¼

 · ·

ÐÓ

·

Insert, Meld. See decreasekey. 

Ô

¡

·

 ÐÓ Ò  ÐÓ

Ü Ü



·½

Deletemin. Our analysis focuses on one couplet 

¼

 ½ (two children of the root). Let Ü bethetreederived

by coupling and accumulating all the right siblings of

Ü Ô´Ü µ Ü  Ü 

·½ ·½ ·½ 

 .Let and

  ÐÓ´ ·  µ

Where the last line follows from ÐÓ

Ô

¼ ¼

Ü 

. Due to the introduction of illusory links

ÐÓ Ò Ü

; if this inequality did not hold then  would

¼

½

may be smaller than . As far as this couplet have already been closed. This one unit is used to pay Ü

is concerned the deletemin performs two linkings:  ´½µ

for Ç comparisons involving this couplet and pos-

¼

Ü Ü ·½ with  and the winner with . There are numerous sibly some others. After the links are established one

cases to analyze, depending on the outcomes of the

Ü Ü

·½

or both of  might be closed, which can only

Ü Ü 

·½

comparisons, and the open/closed states of  reduce the potential further. ¼

and Ü . The cases boil down to three scenarios:

The cases involving a mixed couplet (with one open

¯ Ü Ü

·½ If  are both closed then this leads to fruit- and one closed node) are paid for by (a) the creation of ful comparisons. (Fruitful = reduction in poten- new closed-couplets, or (b) letting a non-mixed couplet tial.)

elsewhere pay for the comparisons of the couplet in ques-

¯ Ü Ü

·½ If  are both open this also leads to fruitful tion. The way the closed-couplet potential works is fairly

comparisons.

Þ Ý Þ Ý

½ ¾ ¾

straightforward. Suppose ½ and are adjacent

¯ Ü Ü Ý Ý Ý Þ

·½ ½ ¾   If  is closed and open (or the opposite) mixed couplets, with open. If defeats then a lot

then this couplet may not produce fruitful com- of potential is released, which can pay for the comparisons

Þ Þ ¾ parisons. However, the number of these unfruit- in both couplets. On the other hand, if ½ and emerge as

ful couplets is dominated by the fruitful ones plus winners (and both lose to the tree derived by accumulating

Ý Þ Þ

½ ¾ the cost of all deletemins. ¾ ’s right siblings) then can form a closed-couplet,

reducing the overall potential by at least 1. This is just a introduced in Section 3 and all have some intuitive mean-  sketch of the arguments to come in Section 4. ing. It is more difficult to explain the  and potentials because they are tailored to the operational properties of In Case 1, and in many cases in Section 4, we “borrow” the pairing heap rather than structural features of the tree.

potential from deletemin operations. Lemma 3 is used to We define the five potentials then sketch their relationships

´ÐÓ Òµ

show that at most Ç units of potential are borrowed, and individual roles within the analysis.

´ÐÓ Òµ implying an amortized cost of Ç per deletemin. This

is the same argument used in [5], though phrased differ-

Ӵܵ ½

 ´Üµ  ¾ ´ÐÓ Òµ

ently. ¾



Ӵܵ ¼ ´Üµ

if

Ü Ü

·½

Lemma 3 If every couplet  charges the deletemin

«´Üµ

´Üµ

operation at most Ó

´Üµ¡ ¾

½

´Üµ

Ó otherwise

´ÐÓ Òµ

 



Ü  · Ü  · Ô´Ü µ

 ·½ ·½

½ Ӵܵ Ó ´Üµ  ½

ÐÓ

 if

Ô´Ü µ

Ӵܵ·½

·½

´Üµ

Ӵܵ  Ó ´Üµ

¾ if

¼ otherwise

ÐÓ´Ò ½µ

units, the total amount charged is at most  .



Ӵܵ

¾ ¼ ¾ ½ ´Üµ  Ó ´Üµ

if Ó

´Üµ

Ü  Ü

¼  Proof: Let ½ be the children of the root to be otherwise

deleted. Notice that the following sum telescopes,

 number of closed couplets

 

 ¾



Ü  · Ü  · Ô´Ü µ

¾ ½ ¾ ¾



 ÐÓ

Ô´Ü µ

 · ´ ´Üµ·«´Üµ·´Üµ ´Üµµ 

¾ Total Pot.

 ½

Ü

È È

 ÐÓ Ü  ÐÓ´´ Ü µ´Ü · ½µµ

 

totaling  if is even and   In a deletemin operation each node has the possibility otherwise. ¾

of making progress in two ways, which correspond to «

¼ ¼ ¼

Ó´Ý µ Ó ´Ý µ ´Ý µ Ó ´Ý µ Ó ´Ý µ ´Ý µ and  potentials. Let and 4 A Better Analysis

be with respect to Ý before and after the deletemin opera-

¼

´Ý µ  ½ ´Ý µ

tion. If, after the operation, Ó and is less than

´Ý µ

One suspects that our analysis from the previous sec- Ó

Òµ Ý

´ÐÓ ,then undergoes an order reduction.Weset

¼  ½

tion could be generalized to show that decreasekeys take ¼

´Ý µ ÑÒ  ¼ ´Ý µ´ÐÓ Òµ  ´ÐÓ Òµ 

Ó .This

½ ¿

Ó´Ý µ ½

´ÐÓ Òµ

Ç time. Rather than consider two orders (open

´ ¾µ¾ ´ÐÓ Òµ 

releases at least ¾ units of -potential,

and closed) we could define three orders, where the poten-

  ½

which, for ¾ sufficiently large compared to ,paysfor

´Üµ ¼

tial of a node Ü would be proportional to at order ,



some linkings and the increases in  « and poten-

½ ¿ ½ ¿ ¾ ¿

´Üµ ÐÓ Ò ·ÐÓ Ò ´Üµ ÐÓ Ò ·

at order 1, or tials. (More on this later.) If Ý fails to undergo an or-

½ ¿

¾ ÐÓ Ò

´Ý µ  ¼

at order 2. Whenever two nodes of the same order der reduction it can still make progress. If Ó and

¼ Ó´Ý µ Ó´Ý µ

´Ý µ  ´Ý µ ´ÐÓ Òµ  ¾ end up in the same couplet we are assured of a fruitful com- then at least ½ units of

parison. However, managing three orders is significantly «-potential are released. This pays for some comparisons

 more complicated because there are new ways in which a and possible increases in  and potentials. The other

deletemin operation can fail to release any potential. The three potentials (    ) represent an accounting scheme to comparisons must be paid for by showing the configuration pay for fruitless comparisons. The most interesting of these

of order 0, 1, and 2 nodes after the deletemin is measurably is the -potential, which represents the bottleneck in our

¼

´Ý µ  Ó ´Ý µ  Ó ´Ý µ

“better” than before. This requires a potential function on whole approach. Suppose Ó ,thatis,the Ý configurations. A huge case analysis ensues. order of Ý ’s parent has become strictly closer to ’s own or-

In this section we attempt a generalized analysis. Fol- der. This is a kind of progress since, if the trend continues, Ý

lowing the idea sketched above we assign each node Ü an will be linked with a node of the same order after less than

´Üµ ¾¼ ½  ½   order Ó ,where is a parameter to linkings. (As we will see, such a linking is always fruitful

be fixed later. It is still useful to make an open/closed dis- in the sense that it coincides with a release of «-potential

tinction; order-0 nodes are closed and all other orders are or an order reduction.) However, in the time between two

Դܵ Ó ´Üµ ӴԴܵµ Ý Ó ´Ý µ

open. The parent of Ü is and refers to im- order reductions on it is not necessarily the case that

Ü Դܵµ

mediately before establishing the link ´ . The over- is increasing, or even non-decreasing. That is, this type of 

all potential function consists of five components:   «    progress is very easily destroyed. Using the potentials we

«    Ý and .The and parts are generalized forms of those can show that, on the average, participates in less than

Ó´Ý µ

Ó ´Ý µ Ó ´Þ µ  Ó ´Ý µ Ó ´Þ µ

¾ unfruitful linkings before its next fruitful one. Con- assume that ; the case when ,

 Ý Þ

sider how the potentials of and might behave in the i.e., Ü underwent an order reduction between linking with

¼

Þ Ü situation depicted in Figure 3. Ý and , can be handled separately. Let be the tree root

obtained by coupling and accumulating the right siblings of

¼

Ó´Ü µ  Þ Ý

Ý and let . We assume are not the rightmost

¼

Ó´Ý µ Ó´Þ µ  Ü

children of Ü and ignore the special case when does not

Þ  Ý  Ü Ü

exist. Let  (where is the

 

¼ ¼

Ý Þ Ü 

size of Ü before linking with and )and .Due 

 to the introduction of illusory links we can only guarantee

Þ Ý

¼

  

that ½ . Generally speaking, if is an evolving ¼

function then  is w.r.t. the moment before the deletemin ¼

and  w.r.t. a moment during or after the deletemin. The

following inequalities hold:



Þ

¼ 

 ÐÓ ´ÐÓ Òµ ¼

ÐÓ if



¼



Ó ´Þ µ¼

¼   ÐÓ ´ÐÓ Òµ

ÐÓ if

Ý



¼   ÐÓ ´ ·  µ ´ÐÓ Òµ

ÐÓ if

¼

¼

Ó ´Ý µ 

During the accumulation linking we assign Ü (the accu-

mulation root) an «-potential of:

 

¼

´Ü µ ¾ · ´µ ¡ ÐÓ

Figure 3. Nodes are labeled with their order. «

¼



Ó ´Ý µ

One can see that Ý has made a kind of progress (

½  ¼

¼

´µ

where

 

Þ  Ó ´Ý µ

 )andthat has lost any progress made so

 ¾ ´ÐÓ Òµ ¼ 

½

¼

Ó´Þ µ   ¼ Ó ´Þ µ Ý

far ( ). Since made progress it only

´µ  ½ ¼

makes sense that it should be responsible for paying for the Two properties of to keep in mind are for

´ ·½µ  ´µ Ò

Ý Þ µ ´Þ Ô´Þ µµ «    

links ´ and .Sinceno or potential has and ,for sufficiently large.

Þ Ý

been released Ý just borrows one unit of potential from the The situation is simple: we link and and the win-

¼

Ü Þ void. In the past both Ý and may have borrowed potential ner with . However, due to the number of parameters in-

to pay for these types of linkings. Suppose the debt of Ý and volved there are several cases to analyze. Factors include

´Ý µ ´Þ µ Ý Þ are and . Because made progress we force it the outcomes of the comparisons, the orders of the nodes

to pay for the two links and take on Þ ’s debt. That is, we set involved, whether the two new links become illusory or

¼ ¼

´Ý µ ´Ý µ·´Þ µ·½  ´Þ µ ¼

 and . One can prove by not, and whether any nodes take an order reduction. Our

Ó´Ý µ

2

´Ý µ  ¾ ½ Ó´Ý µ 

induction that  at all times. Since analysis also must take into account features of the cou-

Ý Þ

´Ò¾ µ the number of links made but not paid for is Ç ,where plets containing and after the deletemin operation. We

Ò is the size of the tree. These linkings can be attributed to make repeated reference to cases (a)–(d) depicted in Fig-

earlier insert operations. ure 4. (Most of the key ideas in the proof can be absorbed Þ

It may be the case that both Ý and make no progress, in by considering only case (a) through Situations 1–4. The

¼ ¼ ¼

Ó ´Ý µ  Ó ´Ý µ Ó ´Þ µ  Ó ´Þ µ  

the sense that and .The and other cases are of lesser importance.)

potentials come into play in this situation. ¼

Ý Ü Lemma 4 After linking Þ and and the winner with ,the In the remainder of this section we show that the amor-

adjusted reduction in «-potential (after borrowing potential

tized cost of deletemin is logarithmic while the cost of de- from the current deletemin operation and future and past

½

´ÐÓ Òµ

creasekey, insert, and meld is on the order of ¾ .

Ô

 ¼

decreasekey operations) is at least ¾ if and at

 ÐÓ ÐÓ Ò Ç ´½µ

We set . Theorem 1 follows. 

 ¾   ¼

least ½ if . In case (a) it is at least 0 and if Þ Ý

The proof focuses on one couplet in a deletemin op- 

    ¼  ¾

the reduction is at least ½ . In case (b) it is

Þ Ý Ó´Þ µ Ó´Ý µ 

eration, where is to the left of .Let , 

    ¼  ¾

at least 2 and if the reduction is at least ½ .

   

and assume wlog that ; the analysis for is 

 ¾

In cases (c) and (d) the reduction is at least ½ .

Ô´Ý µ

symmetric. Let Ü be the root to be deleted. We

¼

Ý Þ  Ü  Proof: Regardless of the final winner among  we 2

This induction hypothesis is actually part of the definition of .There

    ÑÒ 

set its order to be ÑÒ . After address-

Ó´Ý µ  Ó´Þ µ Ô´Ý µ is a small anomaly when ,thatis,when had undergone

ing cases (a)–(d) we consider the effect on our potential Þ an order reduction between its linkings with Ý and . This case is easy to handle separately. function when one or both of the new links become illusory.

Ü



¼

Ü  

W.l.o.g. 

 

´ µ ´µ ´µ ´µ

¼ To or

Þ Ý

¼

Ó´Ü µ



Þ Ý

¼ ¼ ¼ ¼ ¼ ¼

Ü Ü  

   

Ý

¼ ¼

Þ 

¼ ¼

Ý Ü Þ Ü

 

¼ ¼

 

Þ

Ý

¼ ¼ ¼ ¼

 ÑÒ    ÑÒ   ÑÒ    ÑÒ  

(a) (b) (c) (d) Þ Ý

Figure 4. Top left: Ü is the root to be deleted and is the couplet under investigation. We assume

¼

Ó´Þ µ Ó ´Ý µ  Ü Ý

. Top right: is the root of the tree derived from coupling and accumulating all of ’s

¼ ¼

Ü ½ right siblings. If no illusory links were introduced (the size of ) would be ; in general it may

be smaller. Cases (a)–(d) depict the four possible outcomes of the two linkings. Regardless of which

¼

Ü ÑÒ  

node becomes the new root (Þ Ý or ), its order is reduced to .

¼ ¼ ¼ ¼

Þ Ü Ý Ü Þ Ó ´Þ µ

Case (a). Here Ý loses to ,whichlosesto .Weset Case (b). Here and lose to .Weset

¼ ¼

 Ó´Ü µ ÑÒ    « ¿ÐÓ´´ ·  ·  µ µ   

. The adjusted reduction in po- ÑÒ . After borrowing units

´´ ·  ·  µ µ « tential, after borrowing ¾ÐÓ units from from deletemin, the reduction in -potential is log of:

the deletemin operation, is the logarithm of:

     

 ´ µ  ´ µ  ´µ

¼

·  · 

· 

   

 ´ µ  ´ µ

¼ ¼

 ·  ·   ·  · 

 ·   ·  · 

¼

  ·   ·  · 

¼

   

 ´ µ ¿

¼

¼

·  ·  ·  · 

¼

     

 

 ´µ  ´ µ ¾

¼

¡

¼

·  ·  ·  · 

 

·  · 

¡

¼

·  · 

¼ ¾

´· µ´ · · µ´· · µ

     

 ´ µ  ´ µ ¾

 ¼ 

¾

 ·  ·  ·  · 

´ · µ



¾

 ·  

´ ·  µ

 



 

 ´ µ

 

¾

 ´ µ

´ ·  µ



· 

ÐÓ Ò

  ¼ 

 ¾  ¼ 





 

 ´ µ



¾



½ · 

ÐÓ Ò  ´ µ

¾

 ´¾ µ  ¼ 

 

 ´ µ





·  · 

¾

½

   

 ¾     ¼ 

ÐÓ Ò ¾ ÐÓ Ò ¾

½ ½

´¾ µ ¾



 

 

 ´µ



· 

 

¾

½

ÐÓ  ´µ ¾

½

 ¾  ¼ 

 ´¾ µ ¾    

¼



¼

 

  ½     otherwise  otherwise

¼ ¼ ¼

Ý Ü  Þ Ý Ü Ý

Case (c). Here Þ loses to ,whichlosesto .Set If any of undergoes an order reduction, say ,

Ó´Ý µ ½ ¼ ¼

« ´ ¾µ¾ ´ÐÓ Òµ  Ó ´Ü µ ÑÒ  

. The reduction in -potential, after bor- then at least ¾ units of -potential are

·  ·  µ µ «´Ý µ

rowing ÐÓ´´ from the deletemin, is the log released. This pays for an increase in by at most

¼

Ó ´Ý µ ½ ¼

 ¾ ´ÐÓ Òµ Ó ´Ý µ  Ó´Ý µ

of: ½ ,where is the new order,

  ¾

  

 as well an increases in and potentials.

 ´ µ  ´ µ

 ·   ·  ·  · 

Lemma 4 gives us a bound on the reduction in «-

¼

 ·  ·    ·   potential. We analyze the effects on     and -potential

with six case distinctions, which depend only on the relative

¼

 

  

 order of .

 ´µ  ´ µ

¼

¼

·  ·  ·  · 

 

¡

¼

·  · 

¼

Situation 1:  . (Closed couplet) By Lemma 4 ½

the reduction in «-potential is at least 2. We use unit to

 

 ´ µ 

pay for the increase in (since this closed couplet is be-

·  ·  · 

 ´½µ

ing destroyed) and 1 unit to pay for Ç comparisons; see

 Situation 2. The creation of new closed couplets can only

¼ ¼

 

(Consider  and separately) reduce the potential further.

¾

´ ·  µ

  ¼ 



 ¼ Ý

Situation 2:  . (Mixed couplet) If defeats

 

 ´ µ

· 

Þ in the first comparison (that is, we are in case (c) or (d)

 

 otherwise





«  ¾

of Lemma 4) then the reduction in -potential at least ½ .

 ·½

 

 ´ µ

¾ 

 We use one unit to pay for the comparisons, units for

ÐÓ Ò ¾

½

 ·½

 ¾ ¾

´Þ µ ¾

theincreasein  and perhaps for an increase in

¼

´Ü µ Ý

 if we are in case (d). Now suppose that loses the

¼ ¼

Þ Ü  Case (d). In this situation Ý defeats both and .Set

first comparison. The adjusted reduction in « potential is

¼

¾ÐÓ´´ ·  ·  µ µ ´Ý µ ÑÒ   Ó . We borrow units positive in all cases, though in case (a) perhaps too small to from the deletemin operation, for a reduction in «-potential pay for any comparisons.

of: ¼

Ý Þ

After Þ defeats it next forms a couplet with some .

¼

     

Þ Þ

´ µ  ´ µ  ´µ

 If was the winner of its last coupling (as is in this cou-

¼

·  ·  ·  ¼

pling) then there are two cases. If Þ is open then, after

¼ ¼

 ·  ·  · 

 inspecting Situations 3–6, one sees that at least 1 extra unit ¼

of potential was released in the last coupling of Þ ,which

¼

   

 ´ µ ¾ Þ

¼ we use to pay for the comparisons involving . On the other

¼

·  ·  ·  · 

 

¼ ¼

¡ Þ Þ

hand, if Þ is closed then is a closed couplet, implying

·  · 

 a reduction of ½ unit of potential, which pays for our

comparisons.

   

¼

 ´ µ  ´µ

The tricky case is if Þ was the loser of its last cou-

·  ·  · 

 pling. Let us stand back a bit and consider the ways in

¼

  ·  ·  ·  ¼

which a winner/loser coupling like Þ Þ could be created.

Let Õ be a child of the root just before a deletemin and

¼

   

 ´ µ ¾

¼

Õ Õ  Õ Õ

½ Û

and let ¼ be the new children of after the

·  ·  ·  · 

¡ Õ

deletemin operation, in right to left order. Clearly ¼ was

·  · 

coupled with Õ before the deletemin and is therefore a loser.

´Õ Õµ

The edge ½ was created in Case (b) or (d), where the

´ ·  µ´ ·  ·  µ

Õ Õ

winner of the couplet, , defeated the accumulator root, ½

  ¼ 

 in this case. (This type of edge is a spine edge. Spine

 

 ´ µ

 edges are marked with dashed lines in Figure 5.) The

· 

¾

½

 ¾  

 otherwise

´Õ Õµ ´Õ Õµ Û

edges ¾ were all created in Case (a) or



Õ  Õ Û (c), where the winner of the couplet, ¾ in this case,

If either of the new links becomes illusory (in any case was defeated by the accumulator root, Õ in this case. Thus

Þ Ý Õ

(a)–(d)) then we may need to increase the orders of the only loser in this new batch of children is ¼ . Among

¼

Ü Õ  Õ Û

or . The maximum increase in all potentials (including ½ at most 2 can be next coupled with a loser: one

½

     Ç ´¾ ´ÐÓ Òµ µ Õ

)is , which we charge to the future can be coupled with ¼ and another can be coupled with a

decreasekey operation that cuts the new illusory link. future child of Õ . See Figure 5.

units of «-potential are released, which pays for resetting

¼ ¼  ·½

´Ý µ  ´Þ µ ¼ ´Þ µ ¾

 and the increase in by and

¼

´Ý µ´Ü µ

 by at most 1. (Subsequent order reductions pay

  

for increases in with large drops in -potential.)

¼

Ó ´Ý µ  Ó ´Ý µ If we are in cases (a) or (b) then ,

that is, from Ý ’s point of view this comparison made a little

Õ progress since its parent’s order is now closer to its own. ¼

future edge ¼

´Ý µ ´Ý µ·´Üµ·½  ´Þ µ ¼ We set  and . The overall

loser



 ½ ´Ý µ´Þ µ  ¾ ½

reduction in potential is .Since

Õ

¼

¼  ·½ 

Õ



´Ý µ  ¾´¾ ½µ·½ ¾ ½  ¾ ½

we have 

¼

¼ Ó ´Ý µ

loser

 ½

¾ .Inotherwords, is still a valid assignment. If



   ¾

we are in case (a) and then by Lemma 4, ½ units are

´Þ µ

released, which pays for the increase in  .Ifwearein

Õ

½



   ¾

case (b) and then ½ units are released, which pays

¼

´Ü µ

for increases at  . Again, subsequent order reductions

¼

  on Ý Þ  Ü pay for increases in potentials with large

drops in  -potential. To sum up, the overall reduction is at

Ç ´½µ Ý least ½, which pays for linkings: those involving and

Þ and possibly some others described in Situation 2.

   ¼

Situation 5:  . (Open couplet; different

´Þ µ ½ orders) Notice that  . We will use this unit to pay for the comparisons and show that any further fluctuation in

potentials does no harm. If we are in case (a) or (b) then

¼ ¼

Ó´Ý µ Ó ´Ý µ   ´Ý µ ´Ý µ

is unchanged, meaning is

 

still a valid assignment. If we are in case (a) and then



 ¾ «

Figure 5. Dashed links form the spine;they the ½ reduction in -potential can pay for any increase in

´Þ µ «

always come from the second linking in cases  . Similarly, reductions in potential pay for increases

¼

´Ü µ   (b) and (d). A loser node is one that, in the last in  in case (b) when . Cases (c) and (d) are easily coupling pass in which it participated, lost to handled.

its couplet partner.

  ¼ Situation 6:   . (Open/mixed couplet) Up

until now we have been worrying about sudden increases 

in -potential. It is in this situation that finally comes ÕÕ

Since couplet ¼ fell in either case (b) or (d), Lemma 4

into play. Suppose that we are in case (a), that Ý lost to

states that at least 2 units of « potential were released. We

¼

Ü   use one unit to pay for the destruction of a closed couplet Þ which lost to .Assuming , neither of these

comparisons were fruitful in the sense that no « potential

Ó´Õ µ Ó´Õ µ ¼

(if ¼ ; see Situation 1) and 1 unit to pay

was released. Furthermore, neither made progress in the

´½µ Õ

for Ç comparisons including those of the 2 children of

¼

Ó ´Ý µ   Ó ´Ý µ

that are winners but are unlucky enough to be coupled with sense of Situation 4 since and

¼

Ó ´Þ µ  Ó ´Þ µ ´Ý µ

losers. ; in fact, we now need to reduce 

to restore validity. We pay for increases in with the

Ó´Þ µ·½ ·½

´Þ µ ¾ ¾ ´Þ µ

reduction in  , from to zero. (If

 ¼

Situation 3:  . (Open couplet; same order)

    ¼

is not reduced to zero then and ; by Lemma



«  ¾ 

By Lemma 4 the reduction in -potential is at least ½ ,

 ¾ «

4, at least ½ units of -potential are released. This is a

 

which we use to pay for increases in and potential. 

´Þ µ ¼ ´Ý µ  ¾ ½

good case.) Since  and ,setting

¼ ¼

 ´Ý µ  ´Þ µ ¼  

We set , always a valid assignment to , ¼

´Ý µ ¼ ¾ ·½

 leaves us with units leftover to pay for

 ½

 ¾ ¡ ´¾ ½µ

increasing the overall potential by at most . ´½µ

Ç comparisons. Cases (b), (c), and (d) are handled

¼

´Þ µ´Ý µ ´Ü µ

Any of  or mayincreaseby1.Ifanyof



similarly. Again, increases in  due to order reductions

¼

Ý Þ  Ü 

undergoes an order reduction, the drop in -potential ¼ 

on Ý Þ  Ü are paid for with reduction in -potential.

 pays for the minor increases in « ,and potentials.

We have established that the cost of deletemin is

   Ç ´ÐÓ Òµ

Situation 4:  . (Open couplet; different . Analyzing inserts, melds, and decreasekeys is



 ¾ orders) If we are in case (c) or (d) then at least ½ trivial. In these three operations there is exactly one link-

ing; we assign the loser Ü of this linking the minimum order [7] J. Iacono. Improved upper bounds for pairing heaps. In

Ó ½

´Üµ´ÐÓ Òµ  ´ÐÓ Òµ

Ó such that . The increase in Scandinavian Workshop on Algorithm Theory (SWAT, LNCS

½

1851

  Ç ´¾ ´ÐÓ Òµ µ  «  potential is . , pages 32–43, 2000. [8] J. S. Vitter J. T. Stasko. Pairing heaps: Experiments and 5 Discussion and Conclusion analysis. Comm. ACM, 30(3):234–249, 1987. [9] K. Mehlhorn and S. N¨aher. LEDA: A Platform for Combi- We have given the first sub-logarithmic bound on the natorial and Geometric Computing. Cambridge University complexity of the pairing heap’s decreasekey operation. We Press, 2000. conjecture that our bound is not tight, and that Fredman’s [10] B. M. E. Moret and H. D. Shapiro. An empirical assess-

ment of algorithms for constructing a minimum spanning

Òµ lower bound of ª´ÐÓ ÐÓ is tight for sparse instances.

½·ª´½µ tree. In DIMACS Series on Discrete Math. and Theoretical

Ò For dense instances, where Ñ , Fredman [4] claimed that pairing heaps run in linear time. Computer Science, 1994. [11] D. D. Sleator and R. E. Tarjan. Self-adjusting binary search

Conjecture 5 The pairing heap executes any se- trees. J. ACM, 32(3):652–686, 1985. Ò

quence of Ñ operations, including deletemins, [12] D. D. Sleator and R. E. Tarjan. Self-adjusting heaps. SIAM

´Ñ ÐÓ ÐÓ Ò · Ò ÐÓ Òµ in Ç time. In particu- Ñ Ò J. Comput., 15(1):52–69, 1986.

lar, the pairing heap is asymptotically optimal for

½·ª´½µ

Ç ´Ò ÐÓ Ò ÐÓ ÐÓ Òµ Ñ Ò Ñ and .

The primary open question in the area of binary search trees is whether the [11] (or any structure) is dynamically optimal; see [1] for some recent progress on this question. Despite the connection between splay trees and pairing heaps, there is no obvious analogue of dynamic optimality for priority queues. However, the corollaries of dynamic optimality do have natural analogues. For instance, if the pairing heap possessed versions of the working set and dynamic finger properties, this would lead to some very simple adaptive sorting algorithms. In [7] Iacono proved that pairing heaps satisfy a weaker form of the working set property.

Acknowledgment. I would like to thank Amr Elmasry and Irit Katriel for several valuable discussions.

References

[1] E. Demaine, D. Harmon, J. Iacono, and M. Pˇatras¸cu. Dy- namic optimality — almost. In Proceedings 45th An- nual IEEE Symposium on Foundations of Computer Science (FOCS), pages 484–490, 2004. [2] A. Elmasry. Adaptive properties of pairing heaps. Technical Report 2001-29, DIMACS, September 2001. [3] A. Elmasry. Parameterized self-adjusting heaps. J. Algor., 52(2):103–119, 2004. [4] M. L. Fredman. On the efficiency of pairing heaps and re- lated data structures. J. ACM, 46(4):473–501, 1999. [5] M. L. Fredman, R. Sedgewick, D. D. Sleator, and R. E. Tar- jan. The pairing heap: a new form of self-adjusting heap. Algorithmica, 1(1):111–129, 1986. [6] M. L. Fredman and R. E. Tarjan. Fibonacci heaps and their uses in improved network optimization algorithms. J. ACM, 34(3):596–615, 1987.