<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
disjoint-set	B-Algorithm
data	I-Algorithm
structure	I-Algorithm
,	O
also	O
called	O
a	O
union	O
–	O
find	O
data	B-General_Concept
structure	I-General_Concept
or	O
merge	O
–	O
find	O
set	O
,	O
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
that	O
stores	O
a	O
collection	O
of	O
disjoint	B-Algorithm
(	O
non-overlapping	O
)	O
sets	O
.	O
</s>
<s>
Equivalently	O
,	O
it	O
stores	O
a	O
partition	O
of	O
a	O
set	O
into	O
disjoint	B-Algorithm
subsets	O
.	O
</s>
<s>
While	O
there	O
are	O
several	O
ways	O
of	O
implementing	O
disjoint-set	B-Algorithm
data	I-Algorithm
structures	I-Algorithm
,	O
in	O
practice	O
they	O
are	O
often	O
identified	O
with	O
a	O
particular	O
implementation	O
called	O
a	O
disjoint-set	O
forest	O
.	O
</s>
<s>
This	O
is	O
a	O
specialized	O
type	O
of	O
forest	O
which	O
performs	O
unions	O
and	O
finds	O
in	O
near-constant	O
amortized	B-General_Concept
time	I-General_Concept
.	O
</s>
<s>
To	O
perform	O
a	O
sequence	O
of	O
addition	O
,	O
union	O
,	O
or	O
find	O
operations	O
on	O
a	O
disjoint-set	O
forest	O
with	O
nodes	O
requires	O
total	O
time	O
,	O
where	O
is	O
the	O
extremely	O
slow-growing	O
inverse	O
Ackermann	O
function	O
.	O
</s>
<s>
Disjoint-set	O
forests	O
do	O
not	O
guarantee	O
this	O
performance	O
on	O
a	O
per-operation	O
basis	O
.	O
</s>
<s>
Individual	O
union	O
and	O
find	O
operations	O
can	O
take	O
longer	O
than	O
a	O
constant	O
times	O
time	O
,	O
but	O
each	O
operation	O
causes	O
the	O
disjoint-set	O
forest	O
to	O
adjust	O
itself	O
so	O
that	O
successive	O
operations	O
are	O
faster	O
.	O
</s>
<s>
Disjoint-set	O
forests	O
are	O
both	O
asymptotically	B-General_Concept
optimal	I-General_Concept
and	O
practically	O
efficient	O
.	O
</s>
<s>
Disjoint-set	B-Algorithm
data	I-Algorithm
structures	I-Algorithm
play	O
a	O
key	O
role	O
in	O
Kruskal	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
for	O
finding	O
the	O
minimum	O
spanning	O
tree	O
of	O
a	O
graph	O
.	O
</s>
<s>
The	O
importance	O
of	O
minimum	O
spanning	O
trees	O
means	O
that	O
disjoint-set	B-Algorithm
data	I-Algorithm
structures	I-Algorithm
underlie	O
a	O
wide	O
variety	O
of	O
algorithms	O
.	O
</s>
<s>
In	O
addition	O
,	O
disjoint-set	B-Algorithm
data	I-Algorithm
structures	I-Algorithm
also	O
have	O
applications	O
to	O
symbolic	O
computation	O
,	O
as	O
well	O
in	O
compilers	O
,	O
especially	O
for	O
register	O
allocation	O
problems	O
.	O
</s>
<s>
Disjoint-set	O
forests	O
were	O
first	O
described	O
by	O
Bernard	O
A	O
.	O
Galler	O
and	O
Michael	O
J	O
.	O
Fischer	O
in	O
1964	O
.	O
</s>
<s>
In	O
1989	O
,	O
Fredman	O
and	O
Saks	O
showed	O
that	O
(	O
amortized	B-General_Concept
)	O
words	O
must	O
be	O
accessed	O
by	O
any	O
disjoint-set	B-Algorithm
data	I-Algorithm
structure	I-Algorithm
per	O
operation	O
,	O
thereby	O
proving	O
the	O
optimality	O
of	O
the	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
In	O
1991	O
,	O
Galil	O
and	O
Italiano	O
published	O
a	O
survey	O
of	O
data	B-General_Concept
structures	I-General_Concept
for	O
disjoint-sets	O
.	O
</s>
<s>
In	O
2007	O
,	O
Sylvain	O
Conchon	O
and	O
Jean-Christophe	O
Filliâtre	O
developed	O
a	O
semi-persistent	O
version	O
of	O
the	O
disjoint-set	O
forest	O
data	B-General_Concept
structure	I-General_Concept
and	O
formalized	O
its	O
correctness	O
using	O
the	O
proof	O
assistant	O
Coq	B-Application
.	O
</s>
<s>
"	O
Semi-persistent	O
"	O
means	O
that	O
previous	O
versions	O
of	O
the	O
structure	O
are	O
efficiently	O
retained	O
,	O
but	O
accessing	O
previous	O
versions	O
of	O
the	O
data	B-General_Concept
structure	I-General_Concept
invalidates	O
later	O
ones	O
.	O
</s>
<s>
Their	O
fastest	O
implementation	O
achieves	O
performance	O
almost	O
as	O
efficient	O
as	O
the	O
non-persistent	O
algorithm	O
.	O
</s>
<s>
Variants	O
of	O
disjoint-set	B-Algorithm
data	I-Algorithm
structures	I-Algorithm
with	O
better	O
performance	O
on	O
a	O
restricted	O
class	O
of	O
problems	O
have	O
also	O
been	O
considered	O
.	O
</s>
<s>
Each	O
node	O
in	O
a	O
disjoint-set	O
forest	O
consists	O
of	O
a	O
pointer	O
and	O
some	O
auxiliary	O
information	O
,	O
either	O
a	O
size	O
or	O
a	O
rank	O
(	O
but	O
not	O
both	O
)	O
.	O
</s>
<s>
Disjoint-set	B-Algorithm
data	I-Algorithm
structures	I-Algorithm
support	O
three	O
operations	O
:	O
Making	O
a	O
new	O
set	O
containing	O
a	O
new	O
element	O
;	O
Finding	O
the	O
representative	O
of	O
the	O
set	O
containing	O
a	O
given	O
element	O
;	O
and	O
Merging	O
two	O
sets	O
.	O
</s>
<s>
The	O
MakeSet	O
operation	O
adds	O
a	O
new	O
element	O
into	O
a	O
new	O
set	O
containing	O
only	O
the	O
new	O
element	O
,	O
and	O
the	O
new	O
set	O
is	O
added	O
to	O
the	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
If	O
the	O
data	B-General_Concept
structure	I-General_Concept
is	O
instead	O
viewed	O
as	O
a	O
partition	O
of	O
a	O
set	O
,	O
then	O
the	O
MakeSet	O
operation	O
enlarges	O
the	O
set	O
by	O
adding	O
the	O
new	O
element	O
,	O
and	O
it	O
extends	O
the	O
existing	O
partition	O
by	O
putting	O
the	O
new	O
element	O
into	O
a	O
new	O
subset	O
containing	O
only	O
the	O
new	O
element	O
.	O
</s>
<s>
In	O
a	O
disjoint-set	O
forest	O
,	O
MakeSet	O
initializes	O
the	O
node	O
's	O
parent	O
pointer	O
and	O
the	O
node	O
's	O
size	O
or	O
rank	O
.	O
</s>
<s>
As	O
long	O
as	O
memory	O
allocation	O
is	O
an	O
amortized	B-General_Concept
constant-time	I-General_Concept
operation	O
,	O
as	O
it	O
is	O
for	O
a	O
good	O
dynamic	B-Data_Structure
array	I-Data_Structure
implementation	O
,	O
it	O
does	O
not	O
change	O
the	O
asymptotic	O
performance	O
of	O
the	O
random-set	O
forest	O
.	O
</s>
<s>
This	O
updating	O
is	O
an	O
important	O
part	O
of	O
the	O
disjoint-set	O
forest	O
's	O
amortized	B-General_Concept
performance	O
guarantee	O
.	O
</s>
<s>
There	O
are	O
several	O
algorithms	O
for	O
Find	O
that	O
achieve	O
the	O
asymptotically	B-General_Concept
optimal	I-General_Concept
time	O
complexity	O
.	O
</s>
<s>
One	O
family	O
of	O
algorithms	O
,	O
known	O
as	O
path	B-Algorithm
compression	I-Algorithm
,	O
makes	O
every	O
node	O
between	O
the	O
query	O
node	O
and	O
the	O
root	O
point	O
to	O
the	O
root	O
.	O
</s>
<s>
Path	B-Algorithm
compression	I-Algorithm
can	O
be	O
implemented	O
using	O
a	O
simple	O
recursion	O
as	O
follows	O
:	O
</s>
<s>
A	O
disjoint-set	O
forest	O
implementation	O
in	O
which	O
Find	O
does	O
not	O
update	O
parent	O
pointers	O
,	O
and	O
in	O
which	O
Union	O
does	O
not	O
attempt	O
to	O
control	O
tree	O
heights	O
,	O
can	O
have	O
trees	O
with	O
height	O
.	O
</s>
<s>
If	O
an	O
implementation	O
uses	O
path	B-Algorithm
compression	I-Algorithm
alone	O
,	O
then	O
a	O
sequence	O
of	O
MakeSet	O
operations	O
,	O
followed	O
by	O
up	O
to	O
Union	O
operations	O
and	O
Find	O
operations	O
,	O
has	O
a	O
worst-case	O
running	O
time	O
of	O
.	O
</s>
<s>
The	O
combination	O
of	O
path	B-Algorithm
compression	I-Algorithm
,	O
splitting	O
,	O
or	O
halving	O
,	O
with	O
union	O
by	O
size	O
or	O
by	O
rank	O
,	O
reduces	O
the	O
running	O
time	O
for	O
operations	O
of	O
any	O
type	O
,	O
up	O
to	O
of	O
which	O
are	O
MakeSet	O
operations	O
,	O
to	O
.	O
</s>
<s>
This	O
makes	O
the	O
amortized	B-General_Concept
running	I-General_Concept
time	I-General_Concept
of	O
each	O
operation	O
.	O
</s>
<s>
This	O
is	O
asymptotically	B-General_Concept
optimal	I-General_Concept
,	O
meaning	O
that	O
every	O
disjoint	B-Algorithm
set	I-Algorithm
data	I-Algorithm
structure	I-Algorithm
must	O
use	O
amortized	B-General_Concept
time	I-General_Concept
per	O
operation	O
.	O
</s>
<s>
This	O
makes	O
disjoint-set	O
operations	O
practically	O
amortized	B-General_Concept
constant	I-General_Concept
time	I-General_Concept
.	O
</s>
<s>
The	O
precise	O
analysis	O
of	O
the	O
performance	O
of	O
a	O
disjoint-set	O
forest	O
is	O
somewhat	O
intricate	O
.	O
</s>
<s>
However	O
,	O
there	O
is	O
a	O
much	O
simpler	O
analysis	O
that	O
proves	O
that	O
the	O
amortized	B-General_Concept
time	I-General_Concept
for	O
any	O
Find	O
or	O
Union	O
operations	O
on	O
a	O
disjoint-set	O
forest	O
containing	O
objects	O
is	O
,	O
where	O
denotes	O
the	O
iterated	O
logarithm	O
.	O
</s>
<s>
Because	O
of	O
path	B-Algorithm
compression	I-Algorithm
and	O
not	O
accounting	O
for	O
the	O
edge	O
to	O
a	O
root	O
,	O
this	O
sequence	O
contains	O
only	O
different	O
nodes	O
and	O
because	O
of	O
Lemma	O
1	O
we	O
know	O
that	O
the	O
ranks	O
of	O
the	O
nodes	O
in	O
this	O
sequence	O
are	O
strictly	O
increasing	O
.	O
</s>
<s>
Disjoint-set	B-Algorithm
data	I-Algorithm
structures	I-Algorithm
model	O
the	O
partitioning	O
of	O
a	O
set	O
,	O
for	O
example	O
to	O
keep	O
track	O
of	O
the	O
connected	O
components	O
of	O
an	O
undirected	O
graph	O
.	O
</s>
<s>
The	O
Union	B-Algorithm
–	I-Algorithm
Find	I-Algorithm
algorithm	I-Algorithm
is	O
used	O
in	O
high-performance	O
implementations	O
of	O
unification	B-Algorithm
.	O
</s>
<s>
This	O
data	B-General_Concept
structure	I-General_Concept
is	O
used	O
by	O
the	O
Boost	B-Language
Graph	I-Language
Library	I-Language
to	O
implement	O
its	O
functionality	O
.	O
</s>
<s>
It	O
is	O
also	O
a	O
key	O
component	O
in	O
implementing	O
Kruskal	B-Algorithm
's	I-Algorithm
algorithm	I-Algorithm
to	O
find	O
the	O
minimum	O
spanning	O
tree	O
of	O
a	O
graph	O
.	O
</s>
<s>
Note	O
that	O
the	O
regular	O
implementation	O
as	O
disjoint-set	O
forests	O
does	O
not	O
allow	O
the	O
deletion	O
of	O
edges	O
,	O
even	O
without	O
path	B-Algorithm
compression	I-Algorithm
or	O
the	O
rank	O
heuristic	O
.	O
</s>
<s>
Sharir	O
and	O
Agarwal	O
report	O
connections	O
between	O
the	O
worst-case	O
behavior	O
of	O
disjoint-sets	O
and	O
the	O
length	O
of	O
Davenport	O
–	O
Schinzel	O
sequences	O
,	O
a	O
combinatorial	O
structure	O
from	O
computational	O
geometry	O
.	O
</s>
