<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
binomial	B-Application
heap	I-Application
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
that	O
acts	O
as	O
a	O
priority	B-Application
queue	I-Application
but	O
also	O
allows	O
pairs	O
of	O
heaps	B-Application
to	O
be	O
merged	O
.	O
</s>
<s>
It	O
is	O
important	O
as	O
an	O
implementation	O
of	O
the	O
mergeable	B-Application
heap	I-Application
abstract	O
data	O
type	O
(	O
also	O
called	O
meldable	B-Application
heap	I-Application
)	O
,	O
which	O
is	O
a	O
priority	B-Application
queue	I-Application
supporting	O
merge	O
operation	O
.	O
</s>
<s>
It	O
is	O
implemented	O
as	O
a	O
heap	B-Application
similar	O
to	O
a	O
binary	B-Application
heap	I-Application
but	O
using	O
a	O
special	O
tree	O
structure	O
that	O
is	O
different	O
from	O
the	O
complete	O
binary	O
trees	B-Application
used	O
by	O
binary	B-Application
heaps	I-Application
.	O
</s>
<s>
Binomial	B-Application
heaps	I-Application
were	O
invented	O
in	O
1978	O
by	O
Jean	O
Vuillemin	O
.	O
</s>
<s>
A	O
binomial	B-Application
heap	I-Application
is	O
implemented	O
as	O
a	O
set	O
of	O
binomial	O
trees	B-Application
(	O
compare	O
with	O
a	O
binary	B-Application
heap	I-Application
,	O
which	O
has	O
a	O
shape	O
of	O
a	O
single	O
binary	O
tree	O
)	O
,	O
which	O
are	O
defined	O
recursively	O
as	O
follows	O
:	O
</s>
<s>
A	O
binomial	O
tree	O
of	O
order	O
has	O
a	O
root	B-Application
node	I-Application
whose	O
children	O
are	O
roots	O
of	O
binomial	O
trees	B-Application
of	O
orders	O
,	O
,	O
...	O
,	O
2	O
,	O
1	O
,	O
0	O
(	O
in	O
this	O
order	O
)	O
.	O
</s>
<s>
Because	O
of	O
its	O
structure	O
,	O
a	O
binomial	O
tree	O
of	O
order	O
can	O
be	O
constructed	O
from	O
two	O
trees	B-Application
of	O
order	O
by	O
attaching	O
one	O
of	O
them	O
as	O
the	O
leftmost	O
child	O
of	O
the	O
root	O
of	O
the	O
other	O
tree	O
.	O
</s>
<s>
This	O
feature	O
is	O
central	O
to	O
the	O
merge	O
operation	O
of	O
a	O
binomial	B-Application
heap	I-Application
,	O
which	O
is	O
its	O
major	O
advantage	O
over	O
other	O
conventional	O
heaps	B-Application
.	O
</s>
<s>
A	O
binomial	B-Application
heap	I-Application
is	O
implemented	O
as	O
a	O
set	O
of	O
binomial	O
trees	B-Application
that	O
satisfy	O
the	O
binomial	B-Application
heap	I-Application
properties	O
:	O
</s>
<s>
Each	O
binomial	O
tree	O
in	O
a	O
heap	B-Application
obeys	O
the	O
minimum-heap	B-Application
property	I-Application
:	O
the	O
key	O
of	O
a	O
node	O
is	O
greater	O
than	O
or	O
equal	O
to	O
the	O
key	O
of	O
its	O
parent	O
.	O
</s>
<s>
It	O
follows	O
that	O
the	O
smallest	O
key	O
in	O
the	O
entire	O
heap	B-Application
is	O
one	O
of	O
the	O
roots	O
.	O
</s>
<s>
The	O
second	O
property	O
implies	O
that	O
a	O
binomial	B-Application
heap	I-Application
with	O
nodes	O
consists	O
of	O
at	O
most	O
binomial	O
trees	B-Application
,	O
where	O
is	O
the	O
binary	O
logarithm	O
.	O
</s>
<s>
The	O
number	O
and	O
orders	O
of	O
these	O
trees	B-Application
are	O
uniquely	O
determined	O
by	O
the	O
number	O
of	O
nodes	O
:	O
there	O
is	O
one	O
binomial	O
tree	O
for	O
each	O
nonzero	O
bit	O
in	O
the	O
binary	O
representation	O
of	O
the	O
number	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
decimal	O
number	O
13	O
is	O
1101	O
in	O
binary	O
,	O
,	O
and	O
thus	O
a	O
binomial	B-Application
heap	I-Application
with	O
13	O
nodes	O
will	O
consist	O
of	O
three	O
binomial	O
trees	B-Application
of	O
orders	O
3	O
,	O
2	O
,	O
and	O
0	O
(	O
see	O
figure	O
below	O
)	O
.	O
</s>
<s>
The	O
number	O
of	O
different	O
ways	O
that	O
items	O
with	O
distinct	O
keys	O
can	O
be	O
arranged	O
into	O
a	O
binomial	B-Application
heap	I-Application
equals	O
the	O
largest	O
odd	O
divisor	O
of	O
.	O
</s>
<s>
If	O
the	O
items	O
are	O
inserted	O
into	O
a	O
binomial	B-Application
heap	I-Application
in	O
a	O
uniformly	O
random	O
order	O
,	O
each	O
of	O
these	O
arrangements	O
is	O
equally	O
likely	O
.	O
</s>
<s>
Because	O
no	O
operation	O
requires	O
random	O
access	O
to	O
the	O
root	B-Application
nodes	I-Application
of	O
the	O
binomial	O
trees	B-Application
,	O
the	O
roots	O
of	O
the	O
binomial	O
trees	B-Application
can	O
be	O
stored	O
in	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
,	O
ordered	O
by	O
increasing	O
order	O
of	O
the	O
tree	O
.	O
</s>
<s>
These	O
sibling	O
pointers	O
can	O
be	O
interpreted	O
as	O
the	O
next	O
pointers	O
in	O
a	O
linked	B-Data_Structure
list	I-Data_Structure
of	O
the	O
children	O
of	O
each	O
node	O
,	O
but	O
with	O
the	O
opposite	O
order	O
from	O
the	O
linked	B-Data_Structure
list	I-Data_Structure
of	O
roots	O
:	O
from	O
largest	O
to	O
smallest	O
order	O
,	O
rather	O
than	O
vice	O
versa	O
.	O
</s>
<s>
This	O
representation	O
allows	O
two	O
trees	B-Application
of	O
the	O
same	O
order	O
to	O
be	O
linked	O
together	O
,	O
making	O
a	O
tree	O
of	O
the	O
next	O
larger	O
order	O
,	O
in	O
constant	O
time	O
.	O
</s>
<s>
The	O
operation	O
of	O
merging	O
two	O
heaps	B-Application
is	O
used	O
as	O
a	O
subroutine	O
in	O
most	O
other	O
operations	O
.	O
</s>
<s>
A	O
basic	O
subroutine	O
within	O
this	O
procedure	O
merges	O
pairs	O
of	O
binomial	O
trees	B-Application
of	O
the	O
same	O
order	O
.	O
</s>
<s>
This	O
may	O
be	O
done	O
by	O
comparing	O
the	O
keys	O
at	O
the	O
roots	O
of	O
the	O
two	O
trees	B-Application
(	O
the	O
smallest	O
keys	O
in	O
both	O
trees	B-Application
)	O
.	O
</s>
<s>
The	O
root	B-Application
node	I-Application
with	O
the	O
larger	O
key	O
is	O
made	O
into	O
a	O
child	O
of	O
the	O
root	B-Application
node	I-Application
with	O
the	O
smaller	O
key	O
,	O
increasing	O
its	O
order	O
by	O
one	O
:	O
</s>
<s>
To	O
merge	O
two	O
heaps	B-Application
more	O
generally	O
,	O
the	O
lists	O
of	O
roots	O
of	O
both	O
heaps	B-Application
are	O
traversed	O
simultaneously	O
in	O
a	O
manner	O
similar	O
to	O
that	O
of	O
the	O
merge	B-Algorithm
algorithm	I-Algorithm
,	O
</s>
<s>
in	O
a	O
sequence	O
from	O
smaller	O
orders	O
of	O
trees	B-Application
to	O
larger	O
orders	O
.	O
</s>
<s>
When	O
only	O
one	O
of	O
the	O
two	O
heaps	B-Application
being	O
merged	O
contains	O
a	O
tree	O
of	O
order	O
,	O
this	O
tree	O
is	O
moved	O
to	O
the	O
output	O
heap	B-Application
.	O
</s>
<s>
When	O
both	O
of	O
the	O
two	O
heaps	B-Application
contain	O
a	O
tree	O
of	O
order	O
,	O
the	O
two	O
trees	B-Application
are	O
merged	O
to	O
one	O
tree	O
of	O
order	O
so	O
that	O
the	O
minimum-heap	B-Application
property	I-Application
is	O
satisfied	O
.	O
</s>
<s>
It	O
may	O
later	O
become	O
necessary	O
to	O
merge	O
this	O
tree	O
with	O
some	O
other	O
tree	O
of	O
order	O
in	O
one	O
of	O
the	O
two	O
input	O
heaps	B-Application
.	O
</s>
<s>
In	O
the	O
course	O
of	O
the	O
algorithm	O
,	O
it	O
will	O
examine	O
at	O
most	O
three	O
trees	B-Application
of	O
any	O
order	O
,	O
two	O
from	O
the	O
two	O
heaps	B-Application
we	O
merge	O
and	O
one	O
composed	O
of	O
two	O
smaller	O
trees	B-Application
.	O
</s>
<s>
Because	O
each	O
binomial	O
tree	O
in	O
a	O
binomial	B-Application
heap	I-Application
corresponds	O
to	O
a	O
bit	O
in	O
the	O
binary	O
representation	O
of	O
its	O
size	O
,	O
there	O
is	O
an	O
analogy	O
between	O
the	O
merging	O
of	O
two	O
heaps	B-Application
and	O
the	O
binary	O
addition	O
of	O
the	O
sizes	O
of	O
the	O
two	O
heaps	B-Application
,	O
from	O
right-to-left	O
.	O
</s>
<s>
Whenever	O
a	O
carry	O
occurs	O
during	O
addition	O
,	O
this	O
corresponds	O
to	O
a	O
merging	O
of	O
two	O
binomial	O
trees	B-Application
during	O
the	O
merge	O
.	O
</s>
<s>
Inserting	O
a	O
new	O
element	O
to	O
a	O
heap	B-Application
can	O
be	O
done	O
by	O
simply	O
creating	O
a	O
new	O
heap	B-Application
containing	O
only	O
this	O
element	O
and	O
then	O
merging	O
it	O
with	O
the	O
original	O
heap	B-Application
.	O
</s>
<s>
However	O
,	O
this	O
can	O
be	O
sped	O
up	O
using	O
a	O
merge	O
procedure	O
that	O
shortcuts	O
the	O
merge	O
after	O
it	O
reaches	O
a	O
point	O
where	O
only	O
one	O
of	O
the	O
merged	O
heaps	B-Application
has	O
trees	B-Application
of	O
larger	O
order	O
.	O
</s>
<s>
Another	O
way	O
of	O
stating	O
this	O
is	O
that	O
(	O
after	O
logarithmic	O
overhead	O
for	O
the	O
first	O
insertion	O
in	O
a	O
sequence	O
)	O
each	O
successive	O
insert	O
has	O
an	O
amortized	B-General_Concept
time	I-General_Concept
of	O
(	O
i.e.	O
</s>
<s>
A	O
variant	O
of	O
the	O
binomial	B-Application
heap	I-Application
,	O
the	O
skew	B-Application
binomial	I-Application
heap	I-Application
,	O
achieves	O
constant	O
worst	O
case	O
insertion	O
time	O
by	O
using	O
forests	O
whose	O
tree	O
sizes	O
are	O
based	O
on	O
the	O
skew	B-Application
binary	I-Application
number	I-Application
system	I-Application
rather	O
than	O
on	O
the	O
binary	O
number	O
system	O
.	O
</s>
<s>
To	O
find	O
the	O
minimum	O
element	O
of	O
the	O
heap	B-Application
,	O
find	O
the	O
minimum	O
among	O
the	O
roots	O
of	O
the	O
binomial	O
trees	B-Application
.	O
</s>
<s>
To	O
delete	O
the	O
minimum	O
element	O
from	O
the	O
heap	B-Application
,	O
first	O
find	O
this	O
element	O
,	O
remove	O
it	O
from	O
the	O
root	O
of	O
its	O
binomial	O
tree	O
,	O
and	O
obtain	O
a	O
list	O
of	O
its	O
child	O
subtrees	B-Application
(	O
which	O
are	O
each	O
themselves	O
binomial	O
trees	B-Application
,	O
of	O
distinct	O
orders	O
)	O
.	O
</s>
<s>
Transform	O
this	O
list	O
of	O
subtrees	B-Application
into	O
a	O
separate	O
binomial	B-Application
heap	I-Application
by	O
reordering	O
them	O
from	O
smallest	O
to	O
largest	O
order	O
.	O
</s>
<s>
Then	O
merge	O
this	O
heap	B-Application
with	O
the	O
original	O
heap	B-Application
.	O
</s>
<s>
Since	O
each	O
root	O
has	O
at	O
most	O
children	O
,	O
creating	O
this	O
new	O
heap	B-Application
takes	O
time	O
.	O
</s>
<s>
Merging	O
heaps	B-Application
takes	O
time	O
,	O
so	O
the	O
entire	O
delete	O
minimum	O
operation	O
takes	O
time	O
.	O
</s>
<s>
After	O
decreasing	O
the	O
key	O
of	O
an	O
element	O
,	O
it	O
may	O
become	O
smaller	O
than	O
the	O
key	O
of	O
its	O
parent	O
,	O
violating	O
the	O
minimum-heap	B-Application
property	I-Application
.	O
</s>
<s>
If	O
this	O
is	O
the	O
case	O
,	O
exchange	O
the	O
element	O
with	O
its	O
parent	O
,	O
and	O
possibly	O
also	O
with	O
its	O
grandparent	O
,	O
and	O
so	O
on	O
,	O
until	O
the	O
minimum-heap	B-Application
property	I-Application
is	O
no	O
longer	O
violated	O
.	O
</s>
<s>
To	O
delete	O
an	O
element	O
from	O
the	O
heap	B-Application
,	O
decrease	O
its	O
key	O
to	O
negative	O
infinity	O
(	O
or	O
equivalently	O
,	O
to	O
some	O
value	O
lower	O
than	O
any	O
element	O
in	O
the	O
heap	B-Application
)	O
and	O
then	O
delete	O
the	O
minimum	O
in	O
the	O
heap	B-Application
.	O
</s>
