<s>
In	O
number	O
theory	O
,	O
the	O
Calkin	B-Data_Structure
–	I-Data_Structure
Wilf	I-Data_Structure
tree	I-Data_Structure
is	O
a	O
tree	O
in	O
which	O
the	O
vertices	O
correspond	O
one-to-one	B-Algorithm
to	O
the	O
positive	O
rational	O
numbers	O
.	O
</s>
<s>
The	O
sequence	O
of	O
rational	O
numbers	O
in	O
a	O
breadth-first	B-Algorithm
traversal	I-Algorithm
of	O
the	O
Calkin	B-Data_Structure
–	I-Data_Structure
Wilf	I-Data_Structure
tree	I-Data_Structure
is	O
known	O
as	O
the	O
Calkin	O
–	O
Wilf	O
sequence	O
.	O
</s>
<s>
Its	O
sequence	O
of	O
numerators	O
(	O
or	O
,	O
offset	O
by	O
one	O
,	O
denominators	O
)	O
is	O
Stern	O
's	O
diatomic	O
series	O
,	O
and	O
can	O
be	O
computed	O
by	O
the	O
fusc	B-Data_Structure
function	I-Data_Structure
.	O
</s>
<s>
The	O
Calkin	B-Data_Structure
–	I-Data_Structure
Wilf	I-Data_Structure
tree	I-Data_Structure
is	O
named	O
after	O
Neil	O
Calkin	O
and	O
Herbert	O
Wilf	O
,	O
who	O
considered	O
it	O
in	O
a	O
2000	O
paper	O
.	O
</s>
<s>
Stern	O
's	O
diatomic	O
series	O
was	O
formulated	O
much	O
earlier	O
by	O
Moritz	O
Abraham	O
Stern	O
,	O
a	O
19th-century	O
German	O
mathematician	O
who	O
also	O
invented	O
the	O
closely	O
related	O
Stern	B-Data_Structure
–	I-Data_Structure
Brocot	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
<s>
The	O
Calkin	B-Data_Structure
–	I-Data_Structure
Wilf	I-Data_Structure
tree	I-Data_Structure
may	O
be	O
defined	O
as	O
a	O
directed	O
graph	O
in	O
which	O
each	O
positive	O
rational	O
number	O
occurs	O
as	O
a	O
vertex	O
and	O
has	O
one	O
outgoing	O
edge	O
to	O
another	O
vertex	O
,	O
its	O
parent	O
,	O
except	O
for	O
the	O
root	O
of	O
the	O
tree	O
,	O
the	O
number	O
1	O
,	O
which	O
has	O
no	O
parent	O
.	O
</s>
<s>
As	O
a	O
graph	O
with	O
one	O
outgoing	O
edge	O
per	O
vertex	O
and	O
one	O
root	O
reachable	O
by	O
all	O
other	O
vertices	O
,	O
the	O
Calkin	B-Data_Structure
–	I-Data_Structure
Wilf	I-Data_Structure
tree	I-Data_Structure
must	O
indeed	O
be	O
a	O
tree	O
.	O
</s>
<s>
The	O
children	O
of	O
any	O
vertex	O
in	O
the	O
Calkin	B-Data_Structure
–	I-Data_Structure
Wilf	I-Data_Structure
tree	I-Data_Structure
may	O
be	O
computed	O
by	O
inverting	O
the	O
formula	O
for	O
the	O
parents	O
of	O
a	O
vertex	O
.	O
</s>
<s>
As	O
each	O
vertex	O
has	O
two	O
children	O
,	O
the	O
Calkin	B-Data_Structure
–	I-Data_Structure
Wilf	I-Data_Structure
tree	I-Data_Structure
is	O
a	O
binary	O
tree	O
.	O
</s>
<s>
However	O
,	O
it	O
is	O
not	O
a	O
binary	B-Language
search	I-Language
tree	I-Language
:	O
its	O
inorder	O
does	O
not	O
coincide	O
with	O
the	O
sorted	O
order	O
of	O
its	O
vertices	O
.	O
</s>
<s>
However	O
,	O
it	O
is	O
closely	O
related	O
to	O
a	O
different	O
binary	B-Language
search	I-Language
tree	I-Language
on	O
the	O
same	O
set	O
of	O
vertices	O
,	O
the	O
Stern	B-Data_Structure
–	I-Data_Structure
Brocot	I-Data_Structure
tree	I-Data_Structure
:	O
the	O
vertices	O
at	O
each	O
level	O
of	O
the	O
two	O
trees	O
coincide	O
,	O
and	O
are	O
related	O
to	O
each	O
other	O
by	O
a	O
bit-reversal	B-Algorithm
permutation	I-Algorithm
.	O
</s>
<s>
The	O
Calkin	O
–	O
Wilf	O
sequence	O
is	O
the	O
sequence	O
of	O
rational	O
numbers	O
generated	O
by	O
a	O
breadth-first	B-Algorithm
traversal	I-Algorithm
of	O
the	O
Calkin	B-Data_Structure
–	I-Data_Structure
Wilf	I-Data_Structure
tree	I-Data_Structure
,	O
</s>
<s>
Because	O
the	O
Calkin	B-Data_Structure
–	I-Data_Structure
Wilf	I-Data_Structure
tree	I-Data_Structure
contains	O
every	O
positive	O
rational	O
number	O
exactly	O
once	O
,	O
so	O
does	O
this	O
sequence	O
.	O
</s>
<s>
It	O
's	O
also	O
possible	O
to	O
calculate	O
directly	O
from	O
the	O
run-length	B-Algorithm
encoding	I-Algorithm
of	O
the	O
binary	O
representation	O
of	O
:	O
</s>
<s>
In	O
the	O
other	O
direction	O
,	O
using	O
the	O
continued	O
fraction	O
of	O
any	O
as	O
the	O
run-length	B-Algorithm
encoding	I-Algorithm
of	O
a	O
binary	O
number	O
gives	O
back	O
itself	O
.	O
</s>
<s>
A	O
similar	O
conversion	O
between	O
run-length-encoded	O
binary	O
numbers	O
and	O
continued	O
fractions	O
can	O
also	O
be	O
used	O
to	O
evaluate	O
Minkowski	O
's	O
question	O
mark	O
function	O
;	O
however	O
,	O
in	O
the	O
Calkin	B-Data_Structure
–	I-Data_Structure
Wilf	I-Data_Structure
tree	I-Data_Structure
the	O
binary	O
numbers	O
are	O
integers	O
(	O
positions	O
in	O
the	O
breadth-first	B-Algorithm
traversal	I-Algorithm
)	O
while	O
in	O
the	O
question	O
mark	O
function	O
they	O
are	O
real	O
numbers	O
between	O
0	O
and	O
1	O
.	O
</s>
<s>
The	O
th	O
rational	O
number	O
in	O
a	O
breadth-first	B-Algorithm
traversal	I-Algorithm
of	O
the	O
Calkin	B-Data_Structure
–	I-Data_Structure
Wilf	I-Data_Structure
tree	I-Data_Structure
is	O
the	O
number	O
.	O
</s>
<s>
This	O
can	O
be	O
seen	O
from	O
the	O
recurrence	O
defining	O
fusc	B-Data_Structure
:	O
the	O
expressions	O
as	O
a	O
sum	O
of	O
powers	O
of	O
two	O
for	O
an	O
even	O
number	O
either	O
have	O
no	O
1s	O
in	O
them	O
(	O
in	O
which	O
case	O
they	O
are	O
formed	O
by	O
doubling	O
each	O
term	O
in	O
an	O
expression	O
for	O
)	O
or	O
two	O
1s	O
(	O
in	O
which	O
case	O
the	O
rest	O
of	O
the	O
expression	O
is	O
formed	O
by	O
doubling	O
each	O
term	O
in	O
an	O
expression	O
for	O
)	O
,	O
so	O
the	O
number	O
of	O
representations	O
is	O
the	O
sum	O
of	O
the	O
number	O
of	O
representations	O
for	O
and	O
for	O
,	O
matching	O
the	O
recurrence	O
.	O
</s>
<s>
The	O
Calkin	B-Data_Structure
–	I-Data_Structure
Wilf	I-Data_Structure
tree	I-Data_Structure
resembles	O
the	O
Stern	B-Data_Structure
–	I-Data_Structure
Brocot	I-Data_Structure
tree	I-Data_Structure
in	O
that	O
both	O
are	O
binary	O
trees	O
with	O
each	O
positive	O
rational	O
number	O
appearing	O
exactly	O
once	O
.	O
</s>
<s>
One	O
tree	O
can	O
be	O
obtained	O
from	O
the	O
other	O
by	O
performing	O
a	O
bit-reversal	B-Algorithm
permutation	I-Algorithm
on	O
the	O
numbers	O
at	O
each	O
level	O
of	O
the	O
trees	O
.	O
</s>
<s>
Alternatively	O
,	O
the	O
number	O
at	O
a	O
given	O
node	O
of	O
the	O
Calkin	B-Data_Structure
–	I-Data_Structure
Wilf	I-Data_Structure
tree	I-Data_Structure
can	O
be	O
converted	O
into	O
the	O
number	O
at	O
the	O
same	O
position	O
in	O
the	O
Stern	B-Data_Structure
–	I-Data_Structure
Brocot	I-Data_Structure
tree	I-Data_Structure
,	O
and	O
vice	O
versa	O
,	O
by	O
a	O
process	O
involving	O
the	O
reversal	O
of	O
the	O
continued	O
fraction	O
representations	O
of	O
these	O
numbers	O
.	O
</s>
<s>
However	O
,	O
in	O
other	O
ways	O
,	O
they	O
have	O
different	O
properties	O
:	O
for	O
instance	O
,	O
the	O
Stern	B-Data_Structure
–	I-Data_Structure
Brocot	I-Data_Structure
tree	I-Data_Structure
is	O
a	O
binary	B-Language
search	I-Language
tree	I-Language
:	O
the	O
left-to-right	O
traversal	O
order	O
of	O
the	O
tree	O
is	O
the	O
same	O
as	O
the	O
numerical	O
order	O
of	O
the	O
numbers	O
in	O
it	O
.	O
</s>
<s>
This	O
property	O
is	O
not	O
true	O
of	O
the	O
Calkin	B-Data_Structure
–	I-Data_Structure
Wilf	I-Data_Structure
tree	I-Data_Structure
.	O
</s>
