<s>
In	O
computer	B-General_Concept
science	I-General_Concept
a	O
palindrome	B-Data_Structure
tree	I-Data_Structure
,	O
also	O
called	O
an	O
EerTree	O
,	O
is	O
a	O
type	O
of	O
search	O
tree	B-Application
,	O
that	O
allows	O
for	O
fast	O
access	O
to	O
all	O
palindromes	O
contained	O
in	O
a	O
string	O
.	O
</s>
<s>
Palindrome	B-Data_Structure
trees	I-Data_Structure
do	O
this	O
in	O
an	O
online	B-Algorithm
manner	O
,	O
that	O
is	O
it	O
does	O
not	O
require	O
the	O
entire	O
string	O
at	O
the	O
start	O
and	O
can	O
be	O
added	O
to	O
character	O
by	O
character	O
.	O
</s>
<s>
Like	O
most	O
trees	O
,	O
a	O
palindrome	B-Data_Structure
tree	I-Data_Structure
consists	O
of	O
vertices	O
and	O
directed	O
edges	O
.	O
</s>
<s>
Each	O
vertex	O
in	O
the	O
tree	B-Application
represents	O
a	O
palindrome	O
(	O
e.g.	O
</s>
<s>
Where	O
palindrome	B-Data_Structure
trees	I-Data_Structure
differ	O
from	O
regular	O
trees	O
,	O
is	O
that	O
they	O
have	O
two	O
roots	O
(	O
as	O
they	O
are	O
in	O
fact	O
two	O
separate	O
trees	O
)	O
.	O
</s>
<s>
That	O
is	O
,	O
if	O
the	O
character	O
'	O
a	O
 '	O
is	O
appended	O
to	O
both	O
roots	O
the	O
tree	B-Application
will	O
produce	O
'	O
a	O
 '	O
and	O
'	O
aa	O
 '	O
respectively	O
.	O
</s>
<s>
Since	O
a	O
palindrome	B-Data_Structure
tree	I-Data_Structure
follows	O
an	O
online	B-Algorithm
construction	O
,	O
it	O
maintains	O
a	O
pointer	O
to	O
the	O
last	O
palindrome	O
added	O
to	O
the	O
tree	B-Application
.	O
</s>
<s>
To	O
add	O
the	O
next	O
character	O
to	O
the	O
palindrome	B-Data_Structure
tree	I-Data_Structure
,	O
add(x )	O
first	O
checks	O
if	O
the	O
first	O
character	O
before	O
the	O
palindrome	O
matches	O
the	O
character	O
being	O
added	O
,	O
if	O
it	O
does	O
not	O
,	O
the	O
suffix	O
links	O
are	O
followed	O
until	O
a	O
palindrome	O
can	O
be	O
added	O
to	O
the	O
tree	B-Application
.	O
</s>
<s>
Once	O
a	O
palindrome	O
has	O
been	O
found	O
,	O
if	O
it	O
already	O
existed	O
in	O
the	O
tree	B-Application
,	O
there	O
is	O
no	O
work	O
to	O
do	O
.	O
</s>
<s>
If	O
the	O
length	O
of	O
the	O
new	O
palindrome	O
is	O
1	O
,	O
the	O
suffix	O
link	O
points	O
to	O
the	O
root	O
of	O
the	O
palindrome	B-Data_Structure
tree	I-Data_Structure
that	O
represents	O
a	O
length	O
of	O
−1	O
.	O
</s>
<s>
Constructing	O
a	O
palindrome	B-Data_Structure
tree	I-Data_Structure
takes	O
time	O
,	O
where	O
is	O
the	O
length	O
of	O
the	O
string	O
and	O
is	O
the	O
size	O
of	O
the	O
alphabet	O
.	O
</s>
<s>
With	O
calls	O
to	O
add(x )	O
,	O
each	O
call	O
takes	O
amortized	B-General_Concept
time	I-General_Concept
.	O
</s>
<s>
This	O
is	O
a	O
result	O
of	O
each	O
call	O
to	O
add(x )	O
increases	O
the	O
depth	O
of	O
the	O
current	O
vertex	O
(	O
the	O
last	O
palindrome	O
in	O
the	O
tree	B-Application
)	O
by	O
at	O
most	O
one	O
,	O
and	O
searching	O
all	O
possible	O
character	O
edges	O
of	O
a	O
vertex	O
takes	O
time	O
.	O
</s>
<s>
By	O
assigning	O
the	O
cost	O
of	O
moving	O
up	O
and	O
down	O
the	O
tree	B-Application
to	O
each	O
call	O
to	O
add(x )	O
,	O
the	O
cost	O
of	O
moving	O
up	O
the	O
tree	B-Application
more	O
than	O
once	O
is	O
'	O
paid	O
for	O
 '	O
by	O
an	O
equal	O
number	O
of	O
calls	O
to	O
add(x )	O
when	O
moving	O
up	O
the	O
tree	B-Application
did	O
not	O
occur	O
.	O
</s>
<s>
A	O
palindrome	B-Data_Structure
tree	I-Data_Structure
takes	O
space	O
:	O
At	O
most	O
vertices	O
to	O
store	O
the	O
sub-palindromes	O
and	O
two	O
roots	O
,	O
edges	O
,	O
linking	O
the	O
vertices	O
and	O
suffix	O
edges	O
.	O
</s>
