<s>
A	O
pairing	B-Application
heap	I-Application
is	O
a	O
type	O
of	O
heap	B-Application
data	I-Application
structure	I-Application
with	O
relatively	O
simple	O
implementation	O
and	O
excellent	O
practical	O
amortized	B-General_Concept
performance	O
,	O
introduced	O
by	O
Michael	O
Fredman	O
,	O
Robert	O
Sedgewick	O
,	O
Daniel	O
Sleator	O
,	O
and	O
Robert	O
Tarjan	O
in	O
1986	O
.	O
</s>
<s>
Pairing	B-Application
heaps	I-Application
are	O
heap-ordered	B-Application
multiway	O
tree	B-Application
structures	I-Application
,	O
and	O
can	O
be	O
considered	O
simplified	O
Fibonacci	B-Application
heaps	I-Application
.	O
</s>
<s>
They	O
are	O
considered	O
a	O
"	O
robust	O
choice	O
"	O
for	O
implementing	O
such	O
algorithms	O
as	O
Prim	B-Algorithm
's	I-Algorithm
MST	I-Algorithm
algorithm	I-Algorithm
,	O
and	O
support	O
the	O
following	O
operations	O
(	O
assuming	O
a	O
min-heap	B-Application
)	O
:	O
</s>
<s>
find-min	O
:	O
simply	O
return	O
the	O
top	O
element	O
of	O
the	O
heap	B-Application
.	O
</s>
<s>
meld	O
:	O
compare	O
the	O
two	O
root	O
elements	O
,	O
the	O
smaller	O
remains	O
the	O
root	O
of	O
the	O
result	O
,	O
the	O
larger	O
element	O
and	O
its	O
subtree	B-Application
is	O
appended	O
as	O
a	O
child	O
of	O
this	O
root	O
.	O
</s>
<s>
insert	O
:	O
create	O
a	O
new	O
heap	B-Application
for	O
the	O
inserted	O
element	O
and	O
meld	O
into	O
the	O
original	O
heap	B-Application
.	O
</s>
<s>
decrease-key	O
(	O
optional	O
)	O
:	O
remove	O
the	O
subtree	B-Application
rooted	O
at	O
the	O
key	O
to	O
be	O
decreased	O
,	O
replace	O
the	O
key	O
with	O
a	O
smaller	O
key	O
,	O
then	O
meld	O
the	O
result	O
back	O
into	O
the	O
heap	B-Application
.	O
</s>
<s>
delete-min	O
:	O
remove	O
the	O
root	O
and	O
do	O
repeated	O
melds	O
of	O
its	O
subtrees	B-Application
until	O
one	O
tree	O
remains	O
.	O
</s>
<s>
The	O
analysis	O
of	O
pairing	B-Application
heaps	I-Application
 '	O
time	O
complexity	O
was	O
initially	O
inspired	O
by	O
that	O
of	O
splay	B-Data_Structure
trees	I-Data_Structure
.	O
</s>
<s>
The	O
amortized	B-General_Concept
time	I-General_Concept
per	O
delete-min	O
is	O
,	O
and	O
the	O
operations	O
find-min	O
,	O
meld	O
,	O
and	O
insert	O
run	O
in	O
amortized	B-General_Concept
time	I-General_Concept
.	O
</s>
<s>
When	O
a	O
decrease-key	O
operation	O
is	O
added	O
as	O
well	O
,	O
determining	O
the	O
precise	O
asymptotic	O
running	O
time	O
of	O
pairing	B-Application
heaps	I-Application
has	O
turned	O
out	O
to	O
be	O
difficult	O
.	O
</s>
<s>
Initially	O
,	O
the	O
time	O
complexity	O
of	O
this	O
operation	O
was	O
conjectured	O
on	O
empirical	O
grounds	O
to	O
be	O
,	O
but	O
Fredman	O
proved	O
that	O
the	O
amortized	B-General_Concept
time	I-General_Concept
per	O
decrease-key	O
is	O
at	O
least	O
for	O
some	O
sequences	O
of	O
operations	O
.	O
</s>
<s>
Using	O
a	O
different	O
amortization	B-General_Concept
argument	O
,	O
Pettie	O
then	O
proved	O
that	O
insert	O
,	O
meld	O
,	O
and	O
decrease-key	O
all	O
run	O
in	O
amortized	B-General_Concept
time	I-General_Concept
,	O
which	O
is	O
.	O
</s>
<s>
Elmasry	O
later	O
introduced	O
elaborations	O
of	O
pairing	B-Application
heaps	I-Application
(	O
lazy	O
,	O
consolidate	O
)	O
for	O
which	O
decrease-key	O
runs	O
in	O
amortized	B-General_Concept
time	I-General_Concept
and	O
other	O
operations	O
have	O
optimal	O
amortized	B-General_Concept
bounds	O
,	O
but	O
no	O
tight	O
bound	O
is	O
known	O
for	O
the	O
original	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
Although	O
the	O
asymptotic	O
performance	O
of	O
pairing	B-Application
heaps	I-Application
is	O
worse	O
than	O
other	O
priority	O
queue	O
algorithms	O
such	O
as	O
Fibonacci	B-Application
heaps	I-Application
,	O
which	O
perform	O
decrease-key	O
in	O
amortized	B-General_Concept
time	I-General_Concept
,	O
the	O
performance	O
in	O
practice	O
is	O
excellent	O
.	O
</s>
<s>
conducted	O
experiments	O
on	O
pairing	B-Application
heaps	I-Application
and	O
other	O
heap	B-Application
data	I-Application
structures	I-Application
.	O
</s>
<s>
They	O
concluded	O
that	O
d-ary	B-Application
heaps	I-Application
such	O
as	O
binary	O
heaps	B-Application
are	O
faster	O
than	O
all	O
other	O
heap	B-Application
implementations	O
when	O
the	O
decrease-key	O
operation	O
is	O
not	O
needed	O
(	O
and	O
hence	O
there	O
is	O
no	O
need	O
to	O
externally	O
track	O
the	O
location	O
of	O
nodes	O
in	O
the	O
heap	B-Application
)	O
,	O
but	O
that	O
when	O
decrease-key	O
is	O
needed	O
pairing	B-Application
heaps	I-Application
are	O
often	O
faster	O
than	O
d-ary	B-Application
heaps	I-Application
and	O
almost	O
always	O
faster	O
than	O
other	O
pointer-based	O
heaps	B-Application
,	O
including	O
data	B-General_Concept
structures	I-General_Concept
like	O
Fibonacci	B-Application
heaps	I-Application
that	O
are	O
theoretically	O
more	O
efficient	O
.	O
</s>
<s>
examined	O
priority	O
queues	O
specifically	O
for	O
use	O
with	O
Dijkstra	O
's	O
algorithm	O
and	O
concluded	O
that	O
in	O
normal	O
cases	O
using	O
a	O
d-ary	B-Application
heap	I-Application
without	O
decrease-key	O
(	O
instead	O
duplicating	O
nodes	O
on	O
the	O
heap	B-Application
and	O
ignoring	O
redundant	O
instances	O
)	O
resulted	O
in	O
better	O
performance	O
,	O
despite	O
the	O
inferior	O
theoretical	O
performance	O
guarantees	O
.	O
</s>
<s>
A	O
pairing	B-Application
heap	I-Application
is	O
either	O
an	O
empty	O
heap	B-Application
,	O
or	O
a	O
pairing	O
tree	O
consisting	O
of	O
a	O
root	O
element	O
and	O
a	O
possibly	O
empty	O
list	O
of	O
pairing	O
trees	O
.	O
</s>
<s>
The	O
heap	B-Application
ordering	O
property	O
requires	O
that	O
parent	O
of	O
any	O
node	O
is	O
no	O
greater	O
than	O
the	O
node	O
itself	O
.	O
</s>
<s>
The	O
following	O
description	O
assumes	O
a	O
purely	O
functional	O
heap	B-Application
that	O
does	O
not	O
support	O
the	O
decrease-key	O
operation	O
.	O
</s>
<s>
A	O
pointer-based	O
implementation	O
for	O
RAM	B-Application
machines	I-Application
,	O
supporting	O
decrease-key	O
,	O
can	O
be	O
achieved	O
using	O
three	O
pointers	O
per	O
node	O
,	O
by	O
representing	O
the	O
children	O
of	O
a	O
node	O
by	O
a	O
singly-linked	O
list	O
:	O
a	O
pointer	O
to	O
the	O
node	O
's	O
first	O
child	O
,	O
one	O
to	O
its	O
next	O
sibling	O
,	O
and	O
one	O
to	O
its	O
previous	O
sibling	O
(	O
or	O
,	O
for	O
the	O
leftmost	O
sibling	O
,	O
to	O
its	O
parent	O
)	O
.	O
</s>
<s>
The	O
function	O
find-min	O
simply	O
returns	O
the	O
root	O
element	O
of	O
the	O
heap	B-Application
:	O
</s>
<s>
Melding	O
with	O
an	O
empty	O
heap	B-Application
returns	O
the	O
other	O
heap	B-Application
,	O
otherwise	O
a	O
new	O
heap	B-Application
is	O
returned	O
that	O
has	O
the	O
minimum	O
of	O
the	O
two	O
root	O
elements	O
as	O
its	O
root	O
element	O
and	O
just	O
adds	O
the	O
heap	B-Application
with	O
the	O
larger	O
root	O
to	O
the	O
list	O
of	O
subheaps	O
:	O
</s>
<s>
The	O
easiest	O
way	O
to	O
insert	O
an	O
element	O
into	O
a	O
heap	B-Application
is	O
to	O
meld	O
the	O
heap	B-Application
with	O
a	O
new	O
heap	B-Application
containing	O
just	O
this	O
element	O
and	O
an	O
empty	O
list	O
of	O
subheaps	O
:	O
</s>
<s>
The	O
only	O
non-trivial	O
fundamental	O
operation	O
is	O
the	O
deletion	O
of	O
the	O
minimum	O
element	O
from	O
the	O
heap	B-Application
.	O
</s>
<s>
The	O
standard	O
strategy	O
first	O
melds	O
the	O
subheaps	O
in	O
pairs	O
(	O
this	O
is	O
the	O
step	O
that	O
gave	O
this	O
data	B-General_Concept
structure	I-General_Concept
its	O
name	O
)	O
from	O
left	O
to	O
right	O
and	O
then	O
melds	O
the	O
resulting	O
list	O
of	O
heaps	B-Application
from	O
right	O
to	O
left	O
:	O
</s>
