<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
scapegoat	B-Data_Structure
tree	I-Data_Structure
is	O
a	O
self-balancing	B-Data_Structure
binary	I-Data_Structure
search	I-Data_Structure
tree	I-Data_Structure
,	O
invented	O
by	O
Arne	O
Andersson	O
in	O
1989	O
and	O
again	O
by	O
Igal	O
Galperin	O
and	O
Ronald	O
L	O
.	O
Rivest	O
in	O
1993	O
.	O
</s>
<s>
It	O
provides	O
worst-case	O
lookup	O
time	O
(	O
with	O
as	O
the	O
number	O
of	O
entries	O
)	O
and	O
amortized	B-General_Concept
insertion	O
and	O
deletion	O
time	O
.	O
</s>
<s>
Unlike	O
most	O
other	O
self-balancing	B-Data_Structure
binary	I-Data_Structure
search	I-Data_Structure
trees	I-Data_Structure
which	O
also	O
provide	O
worst	O
case	O
lookup	O
time	O
,	O
scapegoat	B-Data_Structure
trees	I-Data_Structure
have	O
no	O
additional	O
per-node	O
memory	O
overhead	O
compared	O
to	O
a	O
regular	O
binary	B-Language
search	I-Language
tree	I-Language
:	O
besides	O
key	O
and	O
value	O
,	O
a	O
node	O
stores	O
only	O
two	O
pointers	O
to	O
the	O
child	O
nodes	O
.	O
</s>
<s>
This	O
makes	O
scapegoat	B-Data_Structure
trees	I-Data_Structure
easier	O
to	O
implement	O
and	O
,	O
due	O
to	O
data	B-Application
structure	I-Application
alignment	I-Application
,	O
can	O
reduce	O
node	O
overhead	O
by	O
up	O
to	O
one-third	O
.	O
</s>
<s>
Instead	O
of	O
the	O
small	O
incremental	O
rebalancing	O
operations	O
used	O
by	O
most	O
balanced	B-Data_Structure
tree	I-Data_Structure
algorithms	O
,	O
scapegoat	B-Data_Structure
trees	I-Data_Structure
rarely	O
but	O
expensively	O
choose	O
a	O
"	O
scapegoat	O
"	O
and	O
completely	O
rebuild	O
the	O
subtree	B-Application
rooted	O
at	O
the	O
scapegoat	O
into	O
a	O
complete	O
binary	O
tree	O
.	O
</s>
<s>
Thus	O
,	O
scapegoat	B-Data_Structure
trees	I-Data_Structure
have	O
worst-case	O
update	O
performance	O
.	O
</s>
<s>
A	O
binary	B-Language
search	I-Language
tree	I-Language
is	O
said	O
to	O
be	O
weight-balanced	O
if	O
half	O
the	O
nodes	O
are	O
on	O
the	O
left	O
of	O
the	O
root	O
,	O
and	O
half	O
on	O
the	O
right	O
.	O
</s>
<s>
Even	O
a	O
degenerate	O
tree	O
(	O
linked	O
list	O
)	O
satisfies	O
this	O
condition	O
if	O
α	O
=	O
1	O
,	O
whereas	O
an	O
α	O
=	O
0.5	O
would	O
only	O
match	O
almost	O
complete	O
binary	O
trees	B-Application
.	O
</s>
<s>
This	O
makes	O
scapegoat	B-Data_Structure
trees	I-Data_Structure
similar	O
to	O
red	O
–	O
black	O
trees	B-Application
in	O
that	O
they	O
both	O
have	O
restrictions	O
on	O
their	O
height	O
.	O
</s>
<s>
They	O
differ	O
greatly	O
though	O
in	O
their	O
implementations	O
of	O
determining	O
where	O
the	O
rotations	O
(	O
or	O
in	O
the	O
case	O
of	O
scapegoat	B-Data_Structure
trees	I-Data_Structure
,	O
rebalances	O
)	O
take	O
place	O
.	O
</s>
<s>
Whereas	O
red	O
–	O
black	O
trees	B-Application
store	O
additional	O
'	O
color	O
 '	O
information	O
in	O
each	O
node	O
to	O
determine	O
the	O
location	O
,	O
scapegoat	B-Data_Structure
trees	I-Data_Structure
find	O
a	O
scapegoat	O
which	O
is	O
n't	O
α-weight-balanced	O
to	O
perform	O
the	O
rebalance	O
operation	O
on	O
.	O
</s>
<s>
This	O
is	O
loosely	O
similar	O
to	O
AVL	O
trees	B-Application
,	O
in	O
that	O
the	O
actual	O
rotations	O
depend	O
on	O
'	O
balances	O
 '	O
of	O
nodes	O
,	O
but	O
the	O
means	O
of	O
determining	O
the	O
balance	O
differs	O
greatly	O
.	O
</s>
<s>
Since	O
AVL	O
trees	B-Application
check	O
the	O
balance	O
value	O
on	O
every	O
insertion/deletion	O
,	O
it	O
is	O
typically	O
stored	O
in	O
each	O
node	O
;	O
scapegoat	B-Data_Structure
trees	I-Data_Structure
are	O
able	O
to	O
calculate	O
it	O
only	O
as	O
needed	O
,	O
which	O
is	O
only	O
when	O
a	O
scapegoat	O
needs	O
to	O
be	O
found	O
.	O
</s>
<s>
Unlike	O
most	O
other	O
self-balancing	O
search	O
trees	B-Application
,	O
scapegoat	B-Data_Structure
trees	I-Data_Structure
are	O
entirely	O
flexible	O
as	O
to	O
their	O
balancing	O
.	O
</s>
<s>
Lookup	O
is	O
not	O
modified	O
from	O
a	O
standard	O
binary	B-Language
search	I-Language
tree	I-Language
,	O
and	O
has	O
a	O
worst-case	O
time	O
of	O
.	O
</s>
<s>
This	O
is	O
in	O
contrast	O
to	O
splay	B-Data_Structure
trees	I-Data_Structure
which	O
have	O
a	O
worst-case	O
time	O
of	O
.	O
</s>
<s>
The	O
reduced	O
node	O
memory	O
overhead	O
compared	O
to	O
other	O
self-balancing	B-Data_Structure
binary	I-Data_Structure
search	I-Data_Structure
trees	I-Data_Structure
can	O
further	O
improve	O
locality	B-General_Concept
of	I-General_Concept
reference	I-General_Concept
and	O
caching	O
.	O
</s>
<s>
Insertion	O
is	O
implemented	O
with	O
the	O
same	O
basic	O
ideas	O
as	O
an	O
unbalanced	O
binary	B-Language
search	I-Language
tree	I-Language
,	O
however	O
with	O
a	O
few	O
significant	O
changes	O
.	O
</s>
<s>
To	O
rebalance	O
,	O
an	O
entire	O
subtree	B-Application
rooted	O
at	O
a	O
scapegoat	O
undergoes	O
a	O
balancing	O
operation	O
.	O
</s>
<s>
Once	O
the	O
scapegoat	O
is	O
found	O
,	O
the	O
subtree	B-Application
rooted	O
at	O
the	O
scapegoat	O
is	O
completely	O
rebuilt	O
to	O
be	O
perfectly	O
balanced	O
.	O
</s>
<s>
This	O
can	O
be	O
done	O
in	O
time	O
by	O
traversing	O
the	O
nodes	O
of	O
the	O
subtree	B-Application
to	O
find	O
their	O
values	O
in	O
sorted	O
order	O
and	O
recursively	O
choosing	O
the	O
median	O
as	O
the	O
root	O
of	O
the	O
subtree	B-Application
.	O
</s>
<s>
As	O
rebalance	O
operations	O
take	O
time	O
(	O
dependent	O
on	O
the	O
number	O
of	O
nodes	O
of	O
the	O
subtree	B-Application
)	O
,	O
insertion	O
has	O
a	O
worst-case	O
performance	O
of	O
time	O
.	O
</s>
<s>
However	O
,	O
because	O
these	O
worst-case	O
scenarios	O
are	O
spread	O
out	O
,	O
insertion	O
takes	O
amortized	B-General_Concept
time	I-General_Concept
.	O
</s>
<s>
Immediately	O
after	O
rebuilding	O
a	O
subtree	B-Application
rooted	O
at	O
v	O
,	O
I(v )	O
=	O
0	O
.	O
</s>
<s>
Lemma	O
:	O
Immediately	O
before	O
rebuilding	O
the	O
subtree	B-Application
rooted	O
at	O
v	O
,	O
</s>
<s>
Let	O
be	O
the	O
root	O
of	O
a	O
subtree	B-Application
immediately	O
after	O
rebuilding	O
.	O
</s>
<s>
Since	O
before	O
rebuilding	O
,	O
there	O
were	O
insertions	O
into	O
the	O
subtree	B-Application
rooted	O
at	O
that	O
did	O
not	O
result	O
in	O
rebuilding	O
.	O
</s>
<s>
Using	O
aggregate	B-General_Concept
analysis	I-General_Concept
it	O
becomes	O
clear	O
that	O
the	O
amortized	B-General_Concept
cost	O
of	O
an	O
insertion	O
is	O
:	O
</s>
<s>
Scapegoat	B-Data_Structure
trees	I-Data_Structure
are	O
unusual	O
in	O
that	O
deletion	O
is	O
easier	O
than	O
insertion	O
.	O
</s>
<s>
To	O
enable	O
deletion	O
,	O
scapegoat	B-Data_Structure
trees	I-Data_Structure
need	O
to	O
store	O
an	O
additional	O
value	O
with	O
the	O
tree	B-Application
data	I-Application
structure	I-Application
.	O
</s>
<s>
This	O
gives	O
deletion	O
a	O
worst-case	O
performance	O
of	O
time	O
,	O
whereas	O
the	O
amortized	B-General_Concept
time	I-General_Concept
is	O
.	O
</s>
<s>
Suppose	O
the	O
scapegoat	B-Data_Structure
tree	I-Data_Structure
has	O
elements	O
and	O
has	O
just	O
been	O
rebuilt	O
(	O
in	O
other	O
words	O
,	O
it	O
is	O
a	O
complete	O
binary	O
tree	O
)	O
.	O
</s>
<s>
Using	O
aggregate	B-General_Concept
analysis	I-General_Concept
it	O
becomes	O
clear	O
that	O
the	O
amortized	B-General_Concept
cost	O
of	O
a	O
deletion	O
is	O
:	O
</s>
<s>
The	O
name	O
Scapegoat	B-Data_Structure
tree	I-Data_Structure
"[...]	O
is	O
based	O
on	O
the	O
common	O
wisdom	O
that	O
,	O
when	O
something	O
goes	O
wrong	O
,	O
the	O
first	O
thing	O
people	O
tend	O
to	O
do	O
is	O
find	O
someone	O
to	O
blame	O
(	O
the	O
scapegoat	O
)	O
.	O
"	O
</s>
