<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
weight-balanced	O
binary	O
trees	O
(	O
WBTs	O
)	O
are	O
a	O
type	O
of	O
self-balancing	B-Data_Structure
binary	I-Data_Structure
search	I-Data_Structure
trees	I-Data_Structure
that	O
can	O
be	O
used	O
to	O
implement	O
dynamic	O
sets	O
,	O
dictionaries	B-Application
(	O
maps	O
)	O
and	O
sequences	O
.	O
</s>
<s>
Like	O
other	O
self-balancing	O
trees	O
,	O
WBTs	O
store	O
bookkeeping	O
information	O
pertaining	O
to	O
balance	O
in	O
their	O
nodes	O
and	O
perform	O
rotations	B-Data_Structure
to	O
restore	O
balance	O
when	O
it	O
is	O
disturbed	O
by	O
insertion	O
or	O
deletion	O
operations	O
.	O
</s>
<s>
Unlike	O
the	O
balance	O
information	O
in	O
AVL	O
trees	O
(	O
using	O
information	O
about	O
the	O
height	O
of	O
subtrees	O
)	O
and	O
red	O
–	O
black	O
trees	O
(	O
which	O
store	O
a	O
fictional	O
"	O
color	O
"	O
bit	O
)	O
,	O
the	O
bookkeeping	O
information	O
in	O
a	O
WBT	O
is	O
an	O
actually	O
useful	O
property	O
for	O
applications	O
:	O
the	O
number	O
of	O
elements	O
in	O
a	O
tree	O
is	O
equal	O
to	O
the	O
size	O
of	O
its	O
root	O
,	O
and	O
the	O
size	O
information	O
is	O
exactly	O
the	O
information	O
needed	O
to	O
implement	O
the	O
operations	O
of	O
an	O
order	B-Algorithm
statistic	I-Algorithm
tree	I-Algorithm
,	O
viz.	O
,	O
getting	O
the	O
'	O
th	O
largest	O
element	O
in	O
a	O
set	O
or	O
determining	O
an	O
element	O
's	O
index	O
in	O
sorted	O
order	O
.	O
</s>
<s>
Weight-balanced	B-Data_Structure
trees	I-Data_Structure
are	O
popular	O
in	O
the	O
functional	B-Language
programming	I-Language
community	O
and	O
are	O
used	O
to	O
implement	O
sets	O
and	O
maps	O
in	O
MIT	B-Application
Scheme	I-Application
,	O
SLIB	B-Application
and	O
implementations	O
of	O
Haskell	B-Language
.	O
</s>
<s>
A	O
weight-balanced	B-Data_Structure
tree	I-Data_Structure
is	O
a	O
binary	O
search	O
tree	O
that	O
stores	O
the	O
sizes	O
of	O
subtrees	O
in	O
the	O
nodes	O
.	O
</s>
<s>
Operations	O
that	O
modify	O
the	O
tree	O
must	O
make	O
sure	O
that	O
the	O
weight	O
of	O
the	O
left	O
and	O
right	O
subtrees	O
of	O
every	O
node	O
remain	O
within	O
some	O
factor	O
of	O
each	O
other	O
,	O
using	O
the	O
same	O
rebalancing	O
operations	O
used	O
in	O
AVL	O
tree	O
:	O
rotations	B-Data_Structure
and	O
double	O
rotations	B-Data_Structure
.	O
</s>
<s>
Here	O
,	O
is	O
a	O
numerical	O
parameter	O
to	O
be	O
determined	O
when	O
implementing	O
weight	O
balanced	B-Data_Structure
trees	I-Data_Structure
.	O
</s>
<s>
The	O
number	O
of	O
balancing	O
operations	O
required	O
in	O
a	O
sequence	O
of	O
insertions	O
and	O
deletions	O
is	O
linear	O
in	O
,	O
i.e.	O
,	O
balancing	O
takes	O
a	O
constant	O
amount	O
of	O
overhead	O
in	O
an	O
amortized	B-General_Concept
sense	O
.	O
</s>
<s>
While	O
maintaining	O
a	O
tree	O
with	O
the	O
minimum	O
search	O
cost	O
requires	O
four	O
kinds	O
of	O
double	O
rotations	B-Data_Structure
(	O
LL	O
,	O
LR	O
,	O
RL	O
,	O
RR	O
as	O
in	O
an	O
AVL	O
tree	O
)	O
in	O
insert/delete	O
operations	O
,	O
if	O
we	O
desire	O
only	O
logarithmic	O
performance	O
,	O
LR	O
and	O
RL	O
are	O
the	O
only	O
rotations	B-Data_Structure
required	O
in	O
a	O
single	O
top-down	O
pass	O
.	O
</s>
<s>
Several	O
set	O
operations	O
have	O
been	O
defined	O
on	O
weight-balanced	B-Data_Structure
trees	I-Data_Structure
:	O
union	O
,	O
intersection	O
and	O
set	O
difference	O
.	O
</s>
<s>
With	O
the	O
new	O
operations	O
,	O
the	O
implementation	O
of	O
weight-balanced	B-Data_Structure
trees	I-Data_Structure
can	O
be	O
more	O
efficient	O
and	O
highly-parallelizable	O
.	O
</s>
<s>
Join	O
:	O
The	O
function	O
Join	O
is	O
on	O
two	O
weight-balanced	B-Data_Structure
trees	I-Data_Structure
and	O
and	O
a	O
key	O
and	O
will	O
return	O
a	O
tree	O
containing	O
all	O
elements	O
in	O
,	O
as	O
well	O
as	O
.	O
</s>
<s>
Split	O
:	O
To	O
split	O
a	O
weight-balanced	B-Data_Structure
tree	I-Data_Structure
into	O
two	O
smaller	O
trees	O
,	O
those	O
smaller	O
than	O
key	O
x	O
,	O
and	O
those	O
larger	O
than	O
key	O
x	O
,	O
first	O
draw	O
a	O
path	O
from	O
the	O
root	O
by	O
inserting	O
x	O
into	O
the	O
tree	O
.	O
</s>
<s>
This	O
algorithm	O
actually	O
has	O
nothing	O
to	O
do	O
with	O
any	O
special	O
properties	O
of	O
a	O
weight-balanced	B-Data_Structure
tree	I-Data_Structure
,	O
and	O
thus	O
is	O
generic	O
to	O
other	O
balancing	O
schemes	O
such	O
as	O
AVL	O
trees	O
.	O
</s>
<s>
The	O
union	O
of	O
two	O
weight-balanced	B-Data_Structure
trees	I-Data_Structure
and	O
representing	O
sets	O
and	O
,	O
is	O
a	O
weight-balanced	B-Data_Structure
tree	I-Data_Structure
that	O
represents	O
.	O
</s>
<s>
(	O
The	O
algorithm	O
is	O
non-destructive	B-Application
,	O
but	O
an	O
in-place	O
destructive	O
version	O
exists	O
as	O
well	O
.	O
)	O
</s>
<s>
Based	O
on	O
the	O
new	O
functions	O
for	O
union	O
,	O
intersection	O
or	O
difference	O
,	O
either	O
one	O
key	O
or	O
multiple	O
keys	O
can	O
be	O
inserted	O
to	O
or	O
deleted	O
from	O
the	O
weight-balanced	B-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
Since	O
Split	O
and	O
Union	O
call	O
Join	O
but	O
do	O
not	O
deal	O
with	O
the	O
balancing	O
criteria	O
of	O
weight-balanced	B-Data_Structure
trees	I-Data_Structure
directly	O
,	O
such	O
an	O
implementation	O
is	O
usually	O
called	O
the	O
join-based	O
algorithms	O
.	O
</s>
<s>
The	O
complexity	O
of	O
each	O
of	O
union	O
,	O
intersection	O
and	O
difference	O
is	O
for	O
two	O
weight-balanced	B-Data_Structure
trees	I-Data_Structure
of	O
sizes	O
and	O
.	O
</s>
<s>
More	O
importantly	O
,	O
since	O
the	O
recursive	O
calls	O
to	O
union	O
,	O
intersection	O
or	O
difference	O
are	O
independent	O
of	O
each	O
other	O
,	O
they	O
can	O
be	O
executed	O
in	B-Operating_System
parallel	I-Operating_System
with	O
a	O
parallel	B-Operating_System
depth	I-Operating_System
.	O
</s>
