<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
tree	O
is	O
a	O
widely	O
used	O
abstract	O
data	O
type	O
that	O
represents	O
a	O
hierarchical	B-Data_Structure
tree	I-Data_Structure
structure	I-Data_Structure
with	O
a	O
set	O
of	O
connected	O
nodes	B-Data_Structure
.	O
</s>
<s>
Each	O
node	B-Data_Structure
in	O
the	O
tree	O
can	O
be	O
connected	O
to	O
many	O
children	O
(	O
depending	O
on	O
the	O
type	O
of	O
tree	O
)	O
,	O
but	O
must	O
be	O
connected	O
to	O
exactly	O
one	O
parent	O
,	O
except	O
for	O
the	O
root	O
node	B-Data_Structure
,	O
which	O
has	O
no	O
parent	O
.	O
</s>
<s>
These	O
constraints	O
mean	O
there	O
are	O
no	O
cycles	O
or	O
"	O
loops	O
"	O
(	O
no	O
node	B-Data_Structure
can	O
be	O
its	O
own	O
ancestor	O
)	O
,	O
and	O
also	O
that	O
each	O
child	O
can	O
be	O
treated	O
like	O
the	O
root	O
node	B-Data_Structure
of	O
its	O
own	O
subtree	O
,	O
making	O
recursion	O
a	O
useful	O
technique	O
for	O
tree	B-Algorithm
traversal	I-Algorithm
.	O
</s>
<s>
In	O
contrast	O
to	O
linear	O
data	O
structures	O
,	O
many	O
trees	O
cannot	O
be	O
represented	O
by	O
relationships	O
between	O
neighboring	O
nodes	B-Data_Structure
in	O
a	O
single	O
straight	O
line	O
.	O
</s>
<s>
A	O
value	O
or	O
pointer	O
to	O
other	O
data	O
may	O
be	O
associated	O
with	O
every	O
node	B-Data_Structure
in	O
the	O
tree	O
,	O
or	O
sometimes	O
only	O
with	O
the	O
leaf	B-Data_Structure
nodes	I-Data_Structure
,	O
which	O
have	O
no	O
children	O
.	O
</s>
<s>
The	O
abstract	O
data	O
type	O
can	O
be	O
represented	O
in	O
a	O
number	O
of	O
ways	O
,	O
including	O
a	O
list	O
of	O
parents	O
with	O
pointers	O
to	O
children	O
,	O
a	O
list	O
of	O
children	O
with	O
pointers	O
to	O
parents	O
,	O
or	O
a	O
list	O
of	O
nodes	B-Data_Structure
and	O
a	O
separate	O
list	O
of	O
parent-child	O
relations	O
(	O
a	O
specific	O
type	O
of	O
adjacency	B-Data_Structure
list	I-Data_Structure
)	O
.	O
</s>
<s>
Representations	O
might	O
also	O
be	O
more	O
complicated	O
,	O
for	O
example	O
using	O
indexes	B-Data_Structure
or	O
ancestor	O
lists	O
for	O
performance	O
.	O
</s>
<s>
File	B-Application
systems	I-Application
for	O
:	O
</s>
<s>
Natural	B-Language
language	I-Language
processing	I-Language
:	O
</s>
<s>
Tree	B-Data_Structure
structures	I-Data_Structure
are	O
often	O
used	O
for	O
mapping	O
the	O
relationships	O
between	O
things	O
,	O
such	O
as	O
:	O
</s>
<s>
JSON	B-General_Concept
and	O
YAML	B-Protocol
documents	O
can	O
be	O
thought	O
of	O
as	O
trees	O
,	O
but	O
are	O
typically	O
represented	O
by	O
nested	O
lists	O
and	O
dictionaries	B-Application
.	O
</s>
<s>
A	O
node	B-Data_Structure
is	O
a	O
structure	O
which	O
may	O
contain	O
data	O
and	O
connections	O
to	O
other	O
nodes	B-Data_Structure
,	O
sometimes	O
called	O
edges	O
or	O
links	O
.	O
</s>
<s>
Each	O
node	B-Data_Structure
in	O
a	O
tree	O
has	O
zero	O
or	O
more	O
child	B-Data_Structure
nodes	I-Data_Structure
,	O
which	O
are	O
below	O
it	O
in	O
the	O
tree	O
(	O
by	O
convention	O
,	O
trees	O
are	O
drawn	O
with	O
descendants	O
going	O
downwards	O
)	O
.	O
</s>
<s>
A	O
node	B-Data_Structure
that	O
has	O
a	O
child	O
is	O
called	O
the	O
child	O
's	O
parent	O
node	B-Data_Structure
(	O
or	O
superior	O
)	O
.	O
</s>
<s>
All	O
nodes	B-Data_Structure
have	O
exactly	O
one	O
parent	O
,	O
except	O
the	O
topmost	O
root	O
node	B-Data_Structure
,	O
which	O
has	O
none	O
.	O
</s>
<s>
A	O
node	B-Data_Structure
might	O
have	O
many	O
ancestor	O
nodes	B-Data_Structure
,	O
such	O
as	O
the	O
parent	O
's	O
parent	O
.	O
</s>
<s>
Child	B-Data_Structure
nodes	I-Data_Structure
with	O
the	O
same	O
parent	O
are	O
sibling	O
nodes	B-Data_Structure
.	O
</s>
<s>
Some	O
definitions	O
allow	O
a	O
tree	O
to	O
have	O
no	O
nodes	B-Data_Structure
at	O
all	O
,	O
in	O
which	O
case	O
it	O
is	O
called	O
empty	O
.	O
</s>
<s>
An	O
internal	O
node	B-Data_Structure
(	O
also	O
known	O
as	O
an	O
inner	O
node	B-Data_Structure
,	O
inode	O
for	O
short	O
,	O
or	O
branch	O
node	B-Data_Structure
)	O
is	O
any	O
node	B-Data_Structure
of	O
a	O
tree	O
that	O
has	O
child	B-Data_Structure
nodes	I-Data_Structure
.	O
</s>
<s>
Similarly	O
,	O
an	O
external	O
node	B-Data_Structure
(	O
also	O
known	O
as	O
an	O
outer	O
node	B-Data_Structure
,	O
leaf	B-Data_Structure
node	I-Data_Structure
,	O
or	O
terminal	O
node	B-Data_Structure
)	O
is	O
any	O
node	B-Data_Structure
that	O
does	O
not	O
have	O
child	B-Data_Structure
nodes	I-Data_Structure
.	O
</s>
<s>
The	O
height	O
of	O
a	O
node	B-Data_Structure
is	O
the	O
length	O
of	O
the	O
longest	O
downward	O
path	O
to	O
a	O
leaf	O
from	O
that	O
node	B-Data_Structure
.	O
</s>
<s>
The	O
depth	O
of	O
a	O
node	B-Data_Structure
is	O
the	O
length	O
of	O
the	O
path	O
to	O
its	O
root	O
(	O
i.e.	O
,	O
its	O
root	O
path	O
)	O
.	O
</s>
<s>
Thus	O
the	O
root	O
node	B-Data_Structure
has	O
depth	O
zero	O
,	O
leaf	B-Data_Structure
nodes	I-Data_Structure
have	O
height	O
zero	O
,	O
and	O
a	O
tree	O
with	O
only	O
a	O
single	O
node	B-Data_Structure
(	O
hence	O
both	O
a	O
root	O
and	O
leaf	O
)	O
has	O
depth	O
and	O
height	O
zero	O
.	O
</s>
<s>
Conventionally	O
,	O
an	O
empty	O
tree	O
(	O
tree	O
with	O
no	O
nodes	B-Data_Structure
,	O
if	O
such	O
are	O
allowed	O
)	O
has	O
height	O
−1	O
.	O
</s>
<s>
Each	O
non-root	O
node	B-Data_Structure
can	O
be	O
treated	O
as	O
the	O
root	O
node	B-Data_Structure
of	O
its	O
own	O
subtree	O
,	O
which	O
includes	O
that	O
node	B-Data_Structure
and	O
all	O
its	O
descendants	O
.	O
</s>
<s>
Stepping	O
through	O
the	O
items	O
of	O
a	O
tree	O
,	O
by	O
means	O
of	O
the	O
connections	O
between	O
parents	O
and	O
children	O
,	O
is	O
called	O
walking	B-Algorithm
the	I-Algorithm
tree	I-Algorithm
,	O
and	O
the	O
action	O
is	O
a	O
walk	O
of	O
the	O
tree	O
.	O
</s>
<s>
Often	O
,	O
an	O
operation	O
might	O
be	O
performed	O
when	O
a	O
pointer	O
arrives	O
at	O
a	O
particular	O
node	B-Data_Structure
.	O
</s>
<s>
A	O
walk	O
in	O
which	O
each	O
parent	O
node	B-Data_Structure
is	O
traversed	O
before	O
its	O
children	O
is	O
called	O
a	O
pre-order	B-Algorithm
walk	I-Algorithm
;	O
a	O
walk	O
in	O
which	O
the	O
children	O
are	O
traversed	O
before	O
their	O
respective	O
parents	O
are	O
traversed	O
is	O
called	O
a	O
post-order	B-Algorithm
walk	I-Algorithm
;	O
a	O
walk	O
in	O
which	O
a	O
node	B-Data_Structure
's	O
left	O
subtree	O
,	O
then	O
the	O
node	B-Data_Structure
itself	O
,	O
and	O
finally	O
its	O
right	O
subtree	O
are	O
traversed	O
is	O
called	O
an	O
in-order	O
traversal	O
.	O
</s>
<s>
A	O
level-order	O
walk	O
effectively	O
performs	O
a	O
breadth-first	B-Algorithm
search	I-Algorithm
over	O
the	O
entirety	O
of	O
a	O
tree	O
;	O
nodes	B-Data_Structure
are	O
traversed	O
level	O
by	O
level	O
,	O
where	O
the	O
root	O
node	B-Data_Structure
is	O
visited	O
first	O
,	O
followed	O
by	O
its	O
direct	O
child	B-Data_Structure
nodes	I-Data_Structure
and	O
their	O
siblings	O
,	O
followed	O
by	O
its	O
grandchild	O
nodes	B-Data_Structure
and	O
their	O
siblings	O
,	O
etc.	O
,	O
until	O
all	O
nodes	B-Data_Structure
in	O
the	O
tree	O
have	O
been	O
traversed	O
.	O
</s>
<s>
In	O
working	O
memory	O
,	O
nodes	B-Data_Structure
are	O
typically	O
dynamically	B-General_Concept
allocated	I-General_Concept
records	O
with	O
pointers	O
to	O
their	O
children	O
,	O
their	O
parents	O
,	O
or	O
both	O
,	O
as	O
well	O
as	O
any	O
associated	O
data	O
.	O
</s>
<s>
If	O
of	O
a	O
fixed	O
size	O
,	O
the	O
nodes	B-Data_Structure
might	O
be	O
stored	O
in	O
a	O
list	O
.	O
</s>
<s>
Nodes	B-Data_Structure
and	O
relationships	O
between	O
nodes	B-Data_Structure
might	O
be	O
stored	O
in	O
a	O
separate	O
special	O
type	O
of	O
adjacency	B-Data_Structure
list	I-Data_Structure
.	O
</s>
<s>
In	O
relational	B-Application
databases	I-Application
,	O
nodes	B-Data_Structure
are	O
typically	O
represented	O
as	O
table	O
rows	O
,	O
with	O
indexed	O
row	O
IDs	O
facilitating	O
pointers	O
between	O
parents	O
and	O
children	O
.	O
</s>
<s>
Nodes	B-Data_Structure
can	O
also	O
be	O
stored	O
as	O
items	O
in	O
an	O
array	B-Data_Structure
,	O
with	O
relationships	O
between	O
them	O
determined	O
by	O
their	O
positions	O
in	O
the	O
array	B-Data_Structure
(	O
as	O
in	O
a	O
binary	B-Application
heap	I-Application
)	O
.	O
</s>
<s>
This	O
can	O
be	O
modified	O
to	O
allow	O
values	O
as	O
well	O
,	O
as	O
in	O
Lisp	O
S-expressions	B-Protocol
,	O
where	O
the	O
head	O
(	O
value	O
of	O
first	O
term	O
)	O
is	O
the	O
value	O
of	O
the	O
node	B-Data_Structure
,	O
the	O
head	O
of	O
the	O
tail	O
(	O
value	O
of	O
second	O
term	O
)	O
is	O
the	O
left	O
child	O
,	O
and	O
the	O
tail	O
of	O
the	O
tail	O
(	O
list	O
of	O
third	O
and	O
subsequent	O
terms	O
)	O
is	O
the	O
right	O
child	O
.	O
</s>
<s>
In	O
terms	O
of	O
type	O
theory	O
,	O
a	O
tree	O
is	O
an	O
inductive	O
type	O
defined	O
by	O
the	O
constructors	O
(	O
empty	O
forest	O
)	O
and	O
(	O
tree	O
with	O
root	O
node	B-Data_Structure
with	O
given	O
value	O
and	O
children	O
)	O
.	O
</s>
<s>
Viewed	O
as	O
a	O
whole	O
,	O
a	O
tree	O
data	O
structure	O
is	O
an	O
ordered	O
tree	O
,	O
generally	O
with	O
values	O
attached	O
to	O
each	O
node	B-Data_Structure
.	O
</s>
<s>
which	O
determines	O
the	O
direction	O
on	O
the	O
edges	O
(	O
arrows	O
point	O
away	O
from	O
the	O
root	O
;	O
given	O
an	O
edge	O
,	O
the	O
node	B-Data_Structure
that	O
the	O
edge	O
points	O
from	O
is	O
called	O
the	O
parent	O
and	O
the	O
node	B-Data_Structure
that	O
the	O
edge	O
points	O
to	O
is	O
called	O
the	O
child	O
)	O
,	O
together	O
with	O
:	O
</s>
<s>
a	O
value	O
(	O
of	O
some	O
data	O
type	O
)	O
at	O
each	O
node	B-Data_Structure
.	O
</s>
<s>
Often	O
trees	O
have	O
a	O
fixed	O
(	O
more	O
properly	O
,	O
bounded	O
)	O
branching	B-Data_Structure
factor	I-Data_Structure
(	O
outdegree	O
)	O
,	O
particularly	O
always	O
having	O
two	O
child	B-Data_Structure
nodes	I-Data_Structure
(	O
possibly	O
empty	O
,	O
hence	O
at	O
most	O
two	O
non-empty	O
child	B-Data_Structure
nodes	I-Data_Structure
)	O
,	O
hence	O
a	O
"	O
binary	O
tree	O
"	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
empty	O
trees	O
simplify	O
defining	O
fixed	O
branching	B-Data_Structure
factor	I-Data_Structure
:	O
with	O
empty	O
trees	O
allowed	O
,	O
a	O
binary	O
tree	O
is	O
a	O
tree	O
such	O
that	O
every	O
node	B-Data_Structure
has	O
exactly	O
two	O
children	O
,	O
each	O
of	O
which	O
is	O
a	O
tree	O
(	O
possibly	O
empty	O
)	O
.	O
</s>
