<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
leftist	B-Application
tree	I-Application
or	O
leftist	B-Application
heap	I-Application
is	O
a	O
priority	B-Application
queue	I-Application
implemented	O
with	O
a	O
variant	O
of	O
a	O
binary	B-Application
heap	I-Application
.	O
</s>
<s>
Every	O
node	O
x	O
has	O
an	O
s-value	O
which	O
is	O
the	O
distance	O
to	O
the	O
nearest	O
leaf	B-Data_Structure
in	O
subtree	O
rooted	O
at	O
x	O
.	O
</s>
<s>
In	O
contrast	O
to	O
a	O
binary	B-Application
heap	I-Application
,	O
a	O
leftist	B-Application
tree	I-Application
attempts	O
to	O
be	O
very	O
unbalanced	O
.	O
</s>
<s>
In	O
addition	O
to	O
the	O
heap	B-Application
property	I-Application
,	O
leftist	B-Application
trees	I-Application
are	O
maintained	O
so	O
the	O
right	O
descendant	O
of	O
each	O
node	O
has	O
the	O
lower	O
s-value	O
.	O
</s>
<s>
The	O
height-biased	O
leftist	B-Application
tree	I-Application
was	O
invented	O
by	O
Clark	O
Allan	O
Crane	O
.	O
</s>
<s>
A	O
leftist	B-Application
tree	I-Application
is	O
a	O
mergeable	B-Application
heap	I-Application
.	O
</s>
<s>
For	O
insertions	O
,	O
this	O
is	O
slower	O
than	O
Fibonacci	B-Application
heaps	I-Application
,	O
which	O
support	O
insertion	O
in	O
O(1 )	O
(	O
constant	O
)	O
amortized	B-General_Concept
time	I-General_Concept
,	O
and	O
O(log n )	O
worst-case	O
.	O
</s>
<s>
Leftist	B-Application
trees	I-Application
are	O
advantageous	O
because	O
of	O
their	O
ability	O
to	O
merge	O
quickly	O
,	O
compared	O
to	O
binary	B-Application
heaps	I-Application
which	O
take	O
Θ(n )	O
.	O
</s>
<s>
In	O
almost	O
all	O
cases	O
,	O
the	O
merging	O
of	O
skew	B-Application
heaps	I-Application
has	O
better	O
performance	O
.	O
</s>
<s>
However	O
merging	O
leftist	B-Application
heaps	I-Application
has	O
worst-case	O
O(log n )	O
complexity	O
while	O
merging	O
skew	B-Application
heaps	I-Application
has	O
only	O
amortized	B-General_Concept
O(log n )	O
complexity	O
.	O
</s>
<s>
The	O
usual	O
leftist	B-Application
tree	I-Application
is	O
a	O
height-biased	O
leftist	B-Application
tree	I-Application
.	O
</s>
<s>
However	O
,	O
other	O
biases	O
can	O
exist	O
,	O
such	O
as	O
in	O
the	O
weight-biased	O
leftist	B-Application
tree	I-Application
.	O
</s>
<s>
Knowing	O
the	O
shortest	O
path	O
to	O
the	O
nearest	O
missing	O
leaf	B-Data_Structure
in	O
the	O
subtree	O
rooted	O
at	O
x	O
is	O
exactly	O
of	O
s(x )	O
,	O
every	O
node	O
at	O
depth	O
s(x )	O
−1	O
or	O
less	O
has	O
exactly	O
2	O
children	O
since	O
s(x )	O
would	O
have	O
been	O
less	O
if	O
not	O
.	O
</s>
<s>
Most	O
operations	O
on	O
a	O
Height	O
Biased	O
Leftist	B-Application
Tree	I-Application
are	O
done	O
using	O
the	O
merge	O
operation	O
.	O
</s>
<s>
The	O
merge	O
operation	O
takes	O
two	O
Min	O
HBLTs	B-Application
as	O
input	O
and	O
returns	O
a	O
Min	O
HBLT	B-Application
containing	O
all	O
the	O
nodes	O
in	O
the	O
original	O
Min	O
HBLTs	B-Application
put	O
together	O
.	O
</s>
<s>
In	O
case	O
of	O
Min	O
HBLTs	B-Application
,	O
assume	O
we	O
have	O
two	O
trees	O
rooted	O
at	O
A	O
and	O
B	O
where	O
A.key	O
B.key	O
.	O
</s>
<s>
To	O
maintain	O
the	O
leftist	B-Application
tree	I-Application
property	O
,	O
after	O
each	O
merge	O
is	O
done	O
,	O
we	O
check	O
if	O
the	O
S-value	O
of	O
right	O
subtree	O
became	O
bigger	O
than	O
the	O
S-value	O
of	O
left	O
subtree	O
during	O
the	O
recursive	O
merge	O
calls	O
.	O
</s>
<s>
Since	O
we	O
assumed	O
that	O
A	O
's	O
root	O
is	O
greater	O
than	O
B	O
's	O
,	O
the	O
heap	B-Application
property	I-Application
is	O
also	O
maintained	O
.	O
</s>
<s>
An	O
example	O
of	O
how	O
the	O
merge	O
operation	O
in	O
a	O
leftist	B-Application
tree	I-Application
works	O
is	O
depicted	O
.	O
</s>
<s>
Min	O
HBLT	B-Application
,	O
creates	O
a	O
HBLT	B-Application
tree	O
of	O
size	O
one	O
with	O
that	O
node	O
and	O
merges	O
it	O
with	O
the	O
existing	O
tree	O
.	O
</s>
<s>
The	O
Min	O
element	O
in	O
a	O
Min	O
HBLT	B-Application
is	O
the	O
root	O
.	O
</s>
<s>
Thus	O
,	O
in	O
order	O
to	O
delete	O
the	O
Min	O
,	O
the	O
root	O
is	O
deleted	O
and	O
its	O
subtrees	O
are	O
merged	O
to	O
form	O
the	O
new	O
Min	O
HBLT	B-Application
.	O
</s>
<s>
Initializing	O
a	O
height	O
biased	O
leftist	B-Application
tree	I-Application
is	O
primarily	O
done	O
in	O
one	O
of	O
two	O
ways	O
.	O
</s>
<s>
The	O
first	O
is	O
to	O
merge	O
each	O
node	O
one	O
at	O
a	O
time	O
into	O
one	O
HBLT	B-Application
.	O
</s>
<s>
This	O
can	O
initialize	O
a	O
HBLT	B-Application
in	O
O(n )	O
time	O
.	O
</s>
<s>
A	O
min	O
height	O
biased	O
leftist	B-Application
tree	I-Application
is	O
shown	O
.	O
</s>
<s>
To	O
initialize	O
a	O
min	O
HBLT	B-Application
,	O
place	O
each	O
element	O
to	O
be	O
added	O
to	O
the	O
tree	O
into	O
a	O
queue	O
.	O
</s>
<s>
Notice	O
that	O
the	O
freshly	O
created	O
HBLT	B-Application
is	O
added	O
to	O
the	O
end	O
of	O
the	O
queue	O
.	O
</s>
<s>
If	O
we	O
have	O
a	O
pointer	O
to	O
a	O
node	O
x	O
in	O
a	O
Min	O
HBLT	B-Application
,	O
we	O
can	O
delete	O
it	O
as	O
follows	O
:	O
Replace	O
the	O
node	O
x	O
with	O
the	O
result	O
of	O
merging	O
its	O
two	O
subtrees	O
and	O
update	O
the	O
s-values	O
of	O
the	O
nodes	O
on	O
the	O
path	O
from	O
x	O
to	O
the	O
root	O
,	O
swapping	O
the	O
right	O
and	O
left	O
subtrees	O
if	O
necessary	O
to	O
maintain	O
the	O
leftist	B-Application
tree	I-Application
property	O
.	O
</s>
<s>
Leftist	B-Application
trees	I-Application
can	O
also	O
be	O
weight	O
biased	O
.	O
</s>
<s>
WBLTs	O
ensure	O
w( 	O
x.left	O
)	O
≥	O
w( 	O
x.right	O
)	O
for	O
all	O
internal	O
nodes	O
x	O
.	O
WBLT	O
operations	O
ensure	O
this	O
invariant	O
by	O
swapping	O
the	O
children	O
of	O
a	O
node	O
when	O
the	O
right	O
subtree	O
outgrows	O
the	O
left	O
one	O
,	O
just	O
as	O
in	O
HBLT	B-Application
operations	O
.	O
</s>
<s>
Insertions	O
and	O
deletion	O
of	O
the	O
min	O
element	O
can	O
be	O
done	O
in	O
the	O
same	O
as	O
for	O
HBLTs	B-Application
using	O
the	O
merge	O
operation	O
.	O
</s>
<s>
Although	O
WBLTs	O
outperform	O
HBLTs	B-Application
in	O
merge	O
,	O
insertion	O
and	O
deletion	O
of	O
the	O
Min	O
key	O
by	O
a	O
constant	O
factor	O
,	O
the	O
O(log n )	O
bound	O
is	O
not	O
guaranteed	O
when	O
deleting	O
an	O
arbitrary	O
element	O
from	O
WBLTs	O
,	O
since	O
θ(n )	O
nodes	O
have	O
to	O
be	O
traversed	O
.	O
</s>
<s>
If	O
this	O
was	O
an	O
HBLT	B-Application
,	O
then	O
deleting	O
the	O
leaf	B-Data_Structure
node	I-Data_Structure
with	O
key	O
60	O
would	O
take	O
O(1 )	O
time	O
and	O
updating	O
the	O
s-values	O
is	O
not	O
needed	O
since	O
the	O
length	O
of	O
rightmost	O
path	O
for	O
all	O
the	O
nodes	O
does	O
not	O
change	O
.	O
</s>
<s>
Several	O
variations	O
on	O
the	O
basic	O
leftist	B-Application
tree	I-Application
exist	O
,	O
which	O
make	O
only	O
minor	O
changes	O
to	O
the	O
basic	O
algorithm	O
:	O
</s>
