<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
purely	B-Application
functional	I-Application
data	I-Application
structure	I-Application
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
that	O
can	O
be	O
implemented	O
in	O
a	O
purely	O
functional	O
language	O
.	O
</s>
<s>
The	O
main	O
difference	O
between	O
an	O
arbitrary	O
data	B-General_Concept
structure	I-General_Concept
and	O
a	O
purely	O
functional	O
one	O
is	O
that	O
the	O
latter	O
is	O
(	O
strongly	O
)	O
immutable	B-Application
.	O
</s>
<s>
This	O
restriction	O
ensures	O
the	O
data	B-General_Concept
structure	I-General_Concept
possesses	O
the	O
advantages	O
of	O
immutable	B-Application
objects	I-Application
:	O
(	O
full	O
)	O
persistency	B-Application
,	O
quick	O
copy	O
of	O
objects	O
,	O
and	O
thread	B-Operating_System
safety	I-Operating_System
.	O
</s>
<s>
Efficient	O
purely	B-Application
functional	I-Application
data	I-Application
structures	I-Application
may	O
require	O
the	O
use	O
of	O
lazy	O
evaluation	O
and	O
memoization	O
.	O
</s>
<s>
Persistent	B-Application
data	I-Application
structures	I-Application
have	O
the	O
property	O
of	O
keeping	O
previous	O
versions	O
of	O
themselves	O
unmodified	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
structures	O
such	O
as	O
arrays	B-Data_Structure
admit	O
a	O
destructive	B-Application
update	I-Application
,	O
that	O
is	O
,	O
an	O
update	O
which	O
cannot	O
be	O
reversed	O
.	O
</s>
<s>
Formally	O
,	O
a	O
purely	B-Application
functional	I-Application
data	I-Application
structure	I-Application
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
which	O
can	O
be	O
implemented	O
in	O
a	O
purely	O
functional	O
language	O
,	O
such	O
as	O
Haskell	B-Language
.	O
</s>
<s>
In	O
practice	O
,	O
it	O
means	O
that	O
the	O
data	B-General_Concept
structures	I-General_Concept
must	O
be	O
built	O
using	O
only	O
persistent	B-Application
data	I-Application
structures	I-Application
such	O
as	O
tuples	O
,	O
sum	B-Language
types	I-Language
,	O
product	O
types	O
,	O
and	O
basic	O
types	O
such	O
as	O
integers	O
,	O
characters	O
,	O
strings	O
.	O
</s>
<s>
Such	O
a	O
data	B-General_Concept
structure	I-General_Concept
is	O
necessarily	O
persistent	O
.	O
</s>
<s>
However	O
,	O
not	O
all	O
persistent	B-Application
data	I-Application
structures	I-Application
are	O
purely	O
functional	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
persistent	B-Data_Structure
array	I-Data_Structure
is	O
a	O
data-structure	O
which	O
is	O
persistent	O
and	O
which	O
is	O
implemented	O
using	O
an	O
array	O
,	O
thus	O
is	O
not	O
purely	O
functional	O
.	O
</s>
<s>
In	O
the	O
book	O
Purely	B-Application
functional	I-Application
data	I-Application
structures	I-Application
,	O
Okasaki	O
compares	O
destructive	B-Application
updates	I-Application
to	O
master	O
chef	O
's	O
knives	O
.	O
</s>
<s>
Destructive	B-Application
updates	I-Application
cannot	O
be	O
undone	O
,	O
and	O
thus	O
they	O
should	O
not	O
be	O
used	O
unless	O
it	O
is	O
certain	O
that	O
the	O
previous	O
value	O
is	O
not	O
required	O
anymore	O
.	O
</s>
<s>
However	O
,	O
destructive	B-Application
updates	I-Application
can	O
also	O
allow	O
efficiency	O
that	O
can	O
not	O
be	O
obtained	O
using	O
other	O
techniques	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
data	B-General_Concept
structure	I-General_Concept
using	O
an	O
array	O
and	O
destructive	B-Application
updates	I-Application
may	O
be	O
replaced	O
by	O
a	O
similar	O
data	B-General_Concept
structure	I-General_Concept
where	O
the	O
array	O
is	O
replaced	O
by	O
a	O
map	B-Application
,	O
a	O
random	O
access	O
list	O
,	O
or	O
a	O
balanced	B-Data_Structure
tree	I-Data_Structure
,	O
which	O
admits	O
a	O
purely	O
functional	O
implementation	O
.	O
</s>
<s>
A	O
data	B-General_Concept
structure	I-General_Concept
is	O
never	O
inherently	O
functional	O
.	O
</s>
<s>
However	O
,	O
if	O
the	O
language	O
is	O
not	O
purely	O
functional	O
,	O
the	O
run-time	O
system	O
may	O
be	O
unable	O
to	O
guarantee	O
immutability	B-Application
.	O
</s>
<s>
In	O
order	O
to	O
ensure	O
that	O
a	O
data	B-General_Concept
structure	I-General_Concept
is	O
used	O
in	O
a	O
purely	O
functional	O
way	O
in	O
an	O
impure	O
functional	O
language	O
,	O
modules	B-Architecture
or	O
classes	O
can	O
be	O
used	O
to	O
ensure	O
manipulation	O
via	O
authorized	O
functions	O
only	O
.	O
</s>
<s>
requires	O
adding	O
these	O
data	B-General_Concept
structures	I-General_Concept
as	O
explicit	O
outputs	O
.	O
</s>
<s>
For	O
instance	O
,	O
consider	O
a	O
function	O
that	O
accepts	O
a	O
mutable	B-Application
list	O
,	O
removes	O
the	O
first	O
element	O
from	O
the	O
list	O
,	O
and	O
returns	O
that	O
element	O
.	O
</s>
<s>
Such	O
a	O
program	O
is	O
said	O
to	O
be	O
written	O
in	O
store-passing	B-Application
style	I-Application
.	O
</s>
<s>
Here	O
is	O
a	O
list	O
of	O
abstract	O
data	B-General_Concept
structures	I-General_Concept
with	O
purely	O
functional	O
implementations	O
:	O
</s>
<s>
(	O
Multi	O
)	O
set	O
of	O
ordered	O
elements	O
and	O
map	B-Application
indexed	O
by	O
ordered	O
keys	O
,	O
implemented	O
as	O
a	O
red	O
–	O
black	O
tree	O
,	O
or	O
more	O
generally	O
by	O
a	O
search	B-Data_Structure
tree	I-Data_Structure
,	O
</s>
<s>
In	O
his	O
book	O
Purely	B-Application
Functional	I-Application
Data	I-Application
Structures	I-Application
,	O
computer	O
scientist	O
Chris	O
Okasaki	O
describes	O
techniques	O
used	O
to	O
design	O
and	O
implement	O
purely	B-Application
functional	I-Application
data	I-Application
structures	I-Application
,	O
a	O
small	O
subset	O
of	O
which	O
are	O
summarized	O
below	O
.	O
</s>
<s>
Therefore	O
,	O
lazy	O
evaluation	O
naturally	O
becomes	O
an	O
important	O
part	O
of	O
the	O
construction	O
of	O
purely	B-Application
functional	I-Application
data	I-Application
structures	I-Application
.	O
</s>
<s>
Therefore	O
,	O
the	O
code	O
of	O
a	O
purely	B-Application
functional	I-Application
data	I-Application
structure	I-Application
can	O
,	O
without	O
loss	O
of	O
efficiency	O
,	O
consider	O
similarly	O
data	O
that	O
will	O
effectively	O
be	O
used	O
and	O
data	O
that	O
will	O
be	O
ignored	O
.	O
</s>
<s>
One	O
of	O
the	O
key	O
tools	O
in	O
building	O
efficient	O
,	O
purely	B-Application
functional	I-Application
data	I-Application
structures	I-Application
is	O
memoization	O
.	O
</s>
<s>
Some	O
data	B-General_Concept
structures	I-General_Concept
,	O
even	O
those	O
that	O
are	O
not	O
purely	O
functional	O
such	O
as	O
dynamic	B-Data_Structure
arrays	I-Data_Structure
,	O
admit	O
operations	O
that	O
are	O
efficient	O
most	O
of	O
the	O
time	O
(	O
e.g.	O
,	O
constant	O
time	O
for	O
dynamic	B-Data_Structure
arrays	I-Data_Structure
)	O
,	O
and	O
rarely	O
inefficient	O
(	O
e.g.	O
,	O
linear	O
time	O
for	O
dynamic	B-Data_Structure
arrays	I-Data_Structure
)	O
.	O
</s>
<s>
Amortization	B-General_Concept
can	O
then	O
be	O
used	O
to	O
prove	O
that	O
the	O
average	O
running	O
time	O
of	O
the	O
operations	O
is	O
efficient	O
.	O
</s>
<s>
In	O
general	O
,	O
having	O
inefficient	O
operations	O
is	O
not	O
acceptable	O
for	O
persistent	B-Application
data	I-Application
structures	I-Application
,	O
because	O
this	O
very	O
operation	O
can	O
be	O
called	O
many	O
times	O
.	O
</s>
<s>
Furthermore	O
,	O
this	O
unpredictability	O
complicates	O
the	O
use	O
of	O
parallelism	B-Operating_System
.	O
</s>
<s>
In	O
order	O
to	O
avoid	O
those	O
problems	O
,	O
some	O
data	B-General_Concept
structures	I-General_Concept
allow	O
for	O
the	O
inefficient	O
operation	O
to	O
be	O
postponed	O
—	O
this	O
is	O
called	O
scheduling	O
.	O
</s>
<s>
Amortized	B-General_Concept
queues	O
are	O
composed	O
of	O
two	O
singly-linked	O
lists	O
:	O
the	O
front	O
and	O
the	O
reversed	O
rear	O
.	O
</s>
<s>
The	O
amortized	B-General_Concept
time	I-General_Concept
complexity	O
of	O
each	O
operation	O
is	O
constant	O
.	O
</s>
