<s>
In	O
graph	O
theory	O
,	O
an	O
m-ary	B-Data_Structure
tree	I-Data_Structure
(	O
also	O
known	O
as	O
n-ary	O
,	O
k-ary	O
or	O
k-way	B-Data_Structure
tree	I-Data_Structure
)	O
is	O
a	O
rooted	O
tree	O
in	O
which	O
each	O
node	O
has	O
no	O
more	O
than	O
m	O
children	O
.	O
</s>
<s>
A	O
binary	O
tree	O
is	O
the	O
special	O
case	O
wherem	O
=	O
2	O
,	O
and	O
a	O
ternary	B-Data_Structure
tree	I-Data_Structure
is	O
another	O
case	O
with	O
m	O
=	O
3	O
that	O
limits	O
its	O
children	O
to	O
three	O
.	O
</s>
<s>
A	O
full	O
m-ary	B-Data_Structure
tree	I-Data_Structure
is	O
an	O
m-ary	B-Data_Structure
tree	I-Data_Structure
where	O
within	O
each	O
level	O
every	O
node	O
has	O
either	O
0	O
or	O
m	O
children	O
.	O
</s>
<s>
A	O
complete	O
m-ary	B-Data_Structure
tree	I-Data_Structure
is	O
an	O
m-ary	B-Data_Structure
tree	I-Data_Structure
which	O
is	O
maximally	O
space	O
efficient	O
.	O
</s>
<s>
A	O
perfect	O
m-ary	B-Data_Structure
tree	I-Data_Structure
is	O
a	O
full	O
m-ary	B-Data_Structure
tree	I-Data_Structure
in	O
which	O
all	O
leaf	B-Data_Structure
nodes	I-Data_Structure
are	O
at	O
the	O
same	O
depth	O
.	O
</s>
<s>
For	O
an	O
m-ary	B-Data_Structure
tree	I-Data_Structure
with	O
height	O
h	O
,	O
the	O
upper	O
bound	O
for	O
the	O
maximum	O
number	O
of	O
leaves	O
is	O
.	O
</s>
<s>
The	O
height	O
h	O
of	O
an	O
m-ary	B-Data_Structure
tree	I-Data_Structure
does	O
not	O
include	O
the	O
root	O
node	O
,	O
with	O
a	O
tree	O
containing	O
only	O
a	O
root	O
node	O
having	O
a	O
height	O
of0	O
.	O
</s>
<s>
The	O
height	O
of	O
a	O
complete	O
m-ary	B-Data_Structure
tree	I-Data_Structure
with	O
n	O
nodes	O
is	O
.	O
</s>
<s>
The	O
total	O
number	O
of	O
possible	O
m-ary	B-Data_Structure
tree	I-Data_Structure
with	O
n	O
nodes	O
is	O
(	O
which	O
is	O
a	O
Catalan	O
number	O
)	O
.	O
</s>
<s>
Traversing	O
a	O
m-ary	B-Data_Structure
tree	I-Data_Structure
is	O
very	O
similar	O
to	O
binary	O
tree	O
traversal	O
.	O
</s>
<s>
Using	O
an	O
array	B-Data_Structure
for	O
representing	O
a	O
m-ary	B-Data_Structure
tree	I-Data_Structure
is	O
inefficient	O
,	O
because	O
most	O
of	O
the	O
nodes	O
in	O
practical	O
applications	O
contain	O
less	O
than	O
m	O
children	O
.	O
</s>
<s>
As	O
a	O
result	O
,	O
this	O
fact	O
leads	O
to	O
a	O
sparse	O
array	B-Data_Structure
with	O
large	O
unused	O
space	O
in	O
the	O
memory	O
.	O
</s>
<s>
Converting	O
an	O
arbitrary	O
m-ary	B-Data_Structure
tree	I-Data_Structure
to	O
a	O
binary	O
tree	O
would	O
only	O
increase	O
the	O
height	O
of	O
the	O
tree	O
by	O
a	O
constant	O
factor	O
and	O
would	O
not	O
affect	O
the	O
overall	O
worst-case	O
time	O
complexity	O
.	O
</s>
<s>
The	O
tree	O
obtained	O
is	O
the	O
desired	O
binary	O
tree	O
obtained	O
from	O
the	O
given	O
m-ary	B-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
m-ary	B-Data_Structure
trees	I-Data_Structure
can	O
also	O
be	O
stored	O
in	O
breadth-first	O
order	O
as	O
an	O
implicit	B-Data_Structure
data	I-Data_Structure
structure	I-Data_Structure
in	O
arrays	O
,	O
and	O
if	O
the	O
tree	O
is	O
a	O
complete	O
m-ary	B-Data_Structure
tree	I-Data_Structure
,	O
this	O
method	O
wastes	O
no	O
space	O
.	O
</s>
<s>
In	O
this	O
compact	O
arrangement	O
,	O
if	O
a	O
node	O
has	O
an	O
index	O
i	O
,	O
its	O
c-th	O
child	O
in	O
range	O
 { 1 , … , m } 	O
is	O
found	O
at	O
index	O
,	O
while	O
its	O
parent	O
(	O
if	O
any	O
)	O
is	O
found	O
at	O
index	O
(	O
assuming	O
the	O
root	O
has	O
index	O
zero	O
,	O
meaning	O
a	O
0-based	O
array	B-Data_Structure
)	O
.	O
</s>
<s>
This	O
method	O
benefits	O
from	O
more	O
compact	O
storage	O
and	O
better	O
locality	B-General_Concept
of	I-General_Concept
reference	I-General_Concept
,	O
particularly	O
during	O
a	O
preorder	O
traversal	O
.	O
</s>
<s>
Each	O
node	O
would	O
have	O
an	O
internal	O
array	B-Data_Structure
for	O
storing	O
pointers	O
to	O
each	O
of	O
its	O
children	O
:	O
</s>
<s>
Compared	O
to	O
array-based	O
implementation	O
,	O
this	O
implementation	O
method	O
has	O
superior	O
space	O
complexity	O
of	O
.	O
</s>
<s>
Listing	O
all	O
possible	O
m-ary	B-Data_Structure
trees	I-Data_Structure
is	O
useful	O
in	O
many	O
disciplines	O
as	O
a	O
way	O
of	O
checking	O
hypotheses	O
or	O
theories	O
.	O
</s>
<s>
Proper	O
representation	O
of	O
m-ary	B-Data_Structure
tree	I-Data_Structure
objects	O
can	O
greatly	O
simplify	O
the	O
generation	O
process	O
.	O
</s>
<s>
One	O
can	O
construct	O
a	O
bit	O
sequence	O
representation	O
using	O
the	O
depth-first	O
search	O
of	O
a	O
m-ary	B-Data_Structure
tree	I-Data_Structure
with	O
n	O
nodes	O
indicating	O
the	O
presence	O
of	O
a	O
node	O
at	O
a	O
given	O
index	O
using	O
binary	O
values	O
.	O
</s>
<s>
Therefore	O
,	O
enumeration	O
over	O
binary	O
strings	O
would	O
not	O
necessarily	O
result	O
in	O
an	O
ordered	O
generation	O
of	O
all	O
m-ary	B-Data_Structure
trees	I-Data_Structure
.	O
</s>
<s>
That	O
is	O
to	O
say	O
that	O
number	O
of	O
zeros	O
in	O
the	O
bit	O
sequence	O
of	O
a	O
m-ary	B-Data_Structure
tree	I-Data_Structure
cannot	O
exceed	O
the	O
total	O
number	O
of	O
null	O
pointers	O
(	O
i.e.	O
,	O
pointers	O
without	O
any	O
child	O
node	O
attached	O
to	O
them	O
)	O
.	O
</s>
<s>
Going	O
back	O
to	O
the	O
table	O
of	O
enumeration	O
of	O
all	O
m-ary	B-Data_Structure
trees	I-Data_Structure
,	O
where	O
and	O
,	O
we	O
can	O
easily	O
observe	O
the	O
apparent	O
jump	O
from	O
"	O
006	O
"	O
to	O
"	O
010	O
"	O
can	O
be	O
explained	O
trivially	O
in	O
an	O
algorithmic	O
fashion	O
as	O
depicted	O
below	O
:	O
</s>
<s>
Loopless	O
enumeration	O
of	O
m-ary	B-Data_Structure
trees	I-Data_Structure
is	O
said	O
to	O
be	O
loopless	O
if	O
after	O
initialization	O
,	O
it	O
generates	O
successive	O
tree	O
objects	O
in	O
.	O
</s>
<s>
For	O
a	O
given	O
a	O
m-ary	B-Data_Structure
tree	I-Data_Structure
T	O
with	O
being	O
one	O
of	O
its	O
nodes	O
and	O
its	O
-th	O
child	O
,	O
a	O
left-t	O
rotation	O
at	O
is	O
done	O
by	O
making	O
the	O
root	O
node	O
,	O
and	O
making	O
and	O
all	O
of	O
its	O
subtrees	O
a	O
child	O
of	O
,	O
additionally	O
we	O
assign	O
the	O
left	O
most	O
children	O
of	O
to	O
and	O
the	O
right	O
most	O
child	O
of	O
stays	O
attached	O
to	O
it	O
while	O
is	O
promoted	O
to	O
root	O
,	O
as	O
shown	O
below	O
:	O
</s>
<s>
Any	O
m-ary	B-Data_Structure
tree	I-Data_Structure
can	O
be	O
transformed	O
to	O
a	O
left-chain	O
tree	O
using	O
sequence	O
of	O
finite	O
left-t	O
rotations	O
for	O
t	O
from	O
2	O
to	O
m	O
.	O
Specifically	O
,	O
this	O
can	O
be	O
done	O
by	O
performing	O
left-t	O
rotations	O
on	O
each	O
node	O
until	O
all	O
of	O
its	O
sub-tree	O
become	O
null	O
at	O
each	O
depth	O
.	O
</s>
<s>
Then	O
,	O
the	O
sequence	O
of	O
number	O
of	O
left-t	O
rotations	O
performed	O
at	O
depth	O
i	O
denoted	O
by	O
defines	O
a	O
codeword	O
of	O
a	O
m-ary	B-Data_Structure
tree	I-Data_Structure
that	O
can	O
be	O
recovered	O
by	O
performing	O
the	O
same	O
sequence	O
of	O
right-t	O
rotations	O
.	O
</s>
<s>
Capturing	O
counts	O
of	O
left-rotations	O
at	O
each	O
depth	O
is	O
a	O
way	O
of	O
encoding	O
an	O
m-ary	B-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
Thus	O
,	O
enumerating	O
all	O
possible	O
legal	O
encoding	O
would	O
helps	O
us	O
to	O
generate	O
all	O
the	O
m-ary	B-Data_Structure
trees	I-Data_Structure
for	O
a	O
given	O
m	O
and	O
n	O
.	O
But	O
,	O
not	O
all	O
sequences	O
of	O
m	O
non-negative	O
integers	O
represent	O
a	O
valid	O
m-ary	B-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
One	O
of	O
the	O
applications	O
of	O
m-ary	B-Data_Structure
tree	I-Data_Structure
is	O
creating	O
a	O
dictionary	O
for	O
validation	O
of	O
acceptable	O
strings	O
.	O
</s>
<s>
There	O
are	O
similar	O
ways	O
to	O
building	O
such	O
a	O
dictionary	O
using	O
B-tree	B-Architecture
,	O
Octree	B-Data_Structure
and/or	O
trie	B-General_Concept
.	O
</s>
