<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
finger	B-Application
tree	I-Application
is	O
a	O
purely	B-Application
functional	I-Application
data	I-Application
structure	I-Application
that	O
can	O
be	O
used	O
to	O
efficiently	O
implement	O
other	O
functional	B-Application
data	I-Application
structures	I-Application
.	O
</s>
<s>
A	O
finger	B-Application
tree	I-Application
gives	O
amortized	B-General_Concept
constant	I-General_Concept
time	I-General_Concept
access	O
to	O
the	O
"	O
fingers	O
"	O
(	O
leaves	O
)	O
of	O
the	O
tree	O
,	O
which	O
is	O
where	O
data	O
is	O
stored	O
,	O
and	O
concatenation	O
and	O
splitting	O
logarithmic	O
time	O
in	O
the	O
size	O
of	O
the	O
smaller	O
piece	O
.	O
</s>
<s>
Ralf	O
Hinze	O
and	O
Ross	O
Paterson	O
state	O
a	O
finger	B-Application
tree	I-Application
is	O
a	O
functional	O
representation	O
of	O
persistent	B-Application
sequences	O
that	O
can	O
access	O
the	O
ends	O
in	O
amortized	B-General_Concept
constant	I-General_Concept
time	I-General_Concept
.	O
</s>
<s>
The	O
structure	O
can	O
also	O
be	O
made	O
into	O
a	O
general	O
purpose	O
data	O
structure	O
by	O
defining	O
the	O
split	O
operation	O
in	O
a	O
general	O
form	O
,	O
allowing	O
it	O
to	O
act	O
as	O
a	O
sequence	O
,	O
priority	B-Application
queue	I-Application
,	O
search	O
tree	O
,	O
or	O
priority	O
search	O
queue	O
,	O
among	O
other	O
varieties	O
of	O
abstract	O
data	O
types	O
.	O
</s>
<s>
In	O
a	O
finger	B-Application
tree	I-Application
,	O
the	O
fingers	O
are	O
structures	O
that	O
point	O
to	O
the	O
ends	O
of	O
a	O
sequence	O
,	O
or	O
the	O
leaf	O
nodes	O
.	O
</s>
<s>
A	O
finger	B-Application
tree	I-Application
is	O
composed	O
of	O
different	O
layers	O
which	O
can	O
be	O
identified	O
by	O
the	O
nodes	O
along	O
its	O
spine	O
.	O
</s>
<s>
Though	O
finger	B-Application
trees	I-Application
are	O
often	O
shown	O
with	O
the	O
spine	O
and	O
branches	O
coming	O
off	O
the	O
sides	O
,	O
there	O
are	O
actually	O
two	O
nodes	O
on	O
the	O
spine	O
at	O
each	O
level	O
that	O
have	O
been	O
paired	O
to	O
make	O
this	O
central	O
spine	O
.	O
</s>
<s>
The	O
closer	O
to	O
the	O
root	O
,	O
the	O
deeper	O
the	O
subtrees	O
of	O
the	O
original	O
tree	O
(	O
the	O
tree	O
before	O
it	O
was	O
a	O
finger	B-Application
tree	I-Application
)	O
the	O
nodes	O
points	O
to	O
.	O
</s>
<s>
We	O
will	O
start	O
this	O
process	O
with	O
a	O
balanced	O
2-3	B-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
For	O
the	O
finger	B-Application
tree	I-Application
to	O
work	O
,	O
all	O
the	O
leaf	O
nodes	O
need	O
to	O
also	O
be	O
level	O
.	O
</s>
<s>
A	O
finger	O
is	O
“	O
a	O
structure	O
providing	O
efficient	O
access	O
to	O
nodes	O
of	O
a	O
tree	O
near	O
a	O
distinguished	O
location.	O
”	O
To	O
make	O
a	O
finger	B-Application
tree	I-Application
we	O
need	O
to	O
put	O
fingers	O
to	O
the	O
right	O
and	O
left	O
ends	O
of	O
the	O
tree	O
and	O
transform	O
it	O
like	O
a	O
zipper	B-Application
.	O
</s>
<s>
This	O
gives	O
us	O
that	O
constant	O
amortized	B-General_Concept
time	I-General_Concept
access	O
to	O
the	O
ends	O
of	O
a	O
sequence	O
.	O
</s>
<s>
To	O
transform	O
,	O
start	O
with	O
the	O
balanced	O
2-3	B-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
Combines	O
the	O
spines	O
to	O
make	O
a	O
standard	O
2-3	O
finger	B-Application
tree	I-Application
.	O
</s>
<s>
In	O
a	O
transformed	O
2-3	B-Data_Structure
tree	I-Data_Structure
it	O
seems	O
that	O
the	O
digit	O
lists	O
at	O
the	O
top	O
level	O
can	O
have	O
a	O
length	O
of	O
two	O
or	O
three	O
with	O
the	O
lower	O
levels	O
only	O
having	O
length	O
of	O
one	O
or	O
two	O
.	O
</s>
<s>
In	O
order	O
for	O
some	O
application	O
of	O
finger	B-Application
trees	I-Application
to	O
run	O
so	O
efficiently	O
,	O
finger	B-Application
trees	I-Application
allow	O
between	O
one	O
and	O
four	O
subtrees	O
on	O
each	O
level	O
.	O
</s>
<s>
The	O
digits	O
of	O
the	O
finger	B-Application
tree	I-Application
can	O
be	O
transformed	O
into	O
a	O
list	O
like	O
so	O
:	O
And	O
so	O
on	O
the	O
image	O
,	O
the	O
top	O
level	O
has	O
elements	O
of	O
type	O
a	O
,	O
the	O
next	O
has	O
elements	O
of	O
type	O
Node	O
a	O
because	O
the	O
node	O
in	O
between	O
the	O
spine	O
and	O
leaves	O
,	O
and	O
this	O
would	O
go	O
on	O
meaning	O
in	O
general	O
that	O
the	O
nth	O
level	O
of	O
the	O
tree	O
has	O
elements	O
of	O
type	O
a	O
,	O
or	O
2-3	B-Data_Structure
trees	I-Data_Structure
of	O
depth	O
n	O
.	O
This	O
means	O
a	O
sequence	O
of	O
n	O
elements	O
is	O
represented	O
by	O
a	O
tree	O
of	O
depth	O
Θ(log n )	O
.	O
</s>
<s>
Finger	B-Application
trees	I-Application
also	O
make	O
efficient	O
deques	B-Application
.	O
</s>
<s>
Whether	O
the	O
structure	O
is	O
persistent	B-Application
or	O
not	O
,	O
all	O
operations	O
take	O
Θ(1 )	O
amortized	B-General_Concept
time	I-General_Concept
.	O
</s>
<s>
The	O
analysis	O
can	O
be	O
compared	O
to	O
Okasaki	O
's	O
implicit	O
deques	B-Application
,	O
the	O
only	O
difference	O
being	O
that	O
the	O
FingerTree	B-Application
type	O
stores	O
Nodes	O
instead	O
of	O
pairs	O
.	O
</s>
<s>
Finger	B-Application
trees	I-Application
can	O
be	O
used	O
to	O
build	O
other	O
trees	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
priority	B-Application
queue	I-Application
can	O
be	O
implemented	O
by	O
labeling	O
the	O
internal	O
nodes	O
by	O
the	O
minimum	O
priority	O
of	O
its	O
children	O
in	O
the	O
tree	O
,	O
or	O
an	O
indexed	O
list/array	O
can	O
be	O
implemented	O
with	O
a	O
labeling	O
of	O
nodes	O
by	O
the	O
count	O
of	O
the	O
leaves	O
in	O
their	O
children	O
.	O
</s>
<s>
Other	O
applications	O
are	O
random-access	O
sequences	O
,	O
described	O
below	O
,	O
ordered	O
sequences	O
,	O
and	O
interval	B-Data_Structure
trees	I-Data_Structure
.	O
</s>
<s>
Finger	B-Application
trees	I-Application
can	O
provide	O
amortized	B-General_Concept
O(1 )	O
pushing	O
,	O
reversing	O
,	O
popping	O
,	O
O(log n )	O
append	O
and	O
split	O
;	O
and	O
can	O
be	O
adapted	O
to	O
be	O
indexed	O
or	O
ordered	O
sequences	O
.	O
</s>
<s>
And	O
like	O
all	O
functional	B-Application
data	I-Application
structures	I-Application
,	O
it	O
is	O
inherently	O
persistent	B-Application
;	O
that	O
is	O
,	O
older	O
versions	O
of	O
the	O
tree	O
are	O
always	O
preserved	O
.	O
</s>
<s>
Finger	B-Application
trees	I-Application
can	O
efficiently	O
implement	O
random-access	O
sequences	O
.	O
</s>
<s>
To	O
do	O
this	O
,	O
we	O
annotate	O
the	O
finger	B-Application
tree	I-Application
with	O
sizes.The	O
N	O
is	O
for	O
natural	O
numbers	O
.	O
</s>
<s>
The	O
use	O
of	O
newtypes	O
does	O
n't	O
cause	O
a	O
run-time	O
penalty	O
in	O
Haskell	B-Language
because	O
in	O
a	O
library	O
,	O
the	O
Size	O
and	O
Elem	O
types	O
would	O
be	O
hidden	O
from	O
the	O
user	O
with	O
wrapper	O
functions	O
.	O
</s>
<s>
Finger	B-Application
trees	I-Application
were	O
first	O
published	O
in	O
1977	O
by	O
Leonidas	O
J	O
.	O
Guibas	O
,	O
and	O
periodically	O
refined	O
since	O
(	O
e.g.	O
</s>
<s>
Finger	B-Application
trees	I-Application
have	O
since	O
been	O
used	O
in	O
the	O
Haskell	B-Language
core	O
libraries	O
(	O
in	O
the	O
implementation	O
of	O
Data.Sequence	O
)	O
,	O
and	O
an	O
implementation	O
in	O
OCaml	B-Language
exists	O
which	O
was	O
derived	O
from	O
a	O
proven-correct	O
Coq	B-Application
implementation	O
.	O
</s>
<s>
There	O
is	O
also	O
a	O
verified	O
implementation	O
in	O
Isabelle	B-Application
(	O
proof	O
assistant	O
)	O
from	O
which	O
programs	O
in	O
Haskell	B-Language
and	O
other	O
(	O
functional	O
)	O
languages	O
can	O
be	O
generated	O
.	O
</s>
<s>
Finger	B-Application
trees	I-Application
can	O
be	O
implemented	O
with	O
or	O
without	O
lazy	O
evaluation	O
,	O
but	O
laziness	O
allows	O
for	O
simpler	O
implementations	O
.	O
</s>
