A Calkin-Wilf tree is an infinite binary tree obtained by starting with the fraction and giving each fraction
the left child
and right child
. It contains every positive rational number exactly once, as a reduced
fraction (Calkin and Wilf 2000, pp. 361-362).
The Stern-Brocot tree is closely related, using successive mediants between neighboring fractions.
At depth ,
each tree contains the same fractions.
Numbering positions from 0 to
from left to right, a fraction
at position
in the Calkin-Wilf tree occurs at the position obtained by reversing the
digits of
written in binary in the Stern-Brocot
tree, retaining leading zeros (Gibbons et al. 2006).
Reading the levels of the Calkin-Wilf tree from left to right gives 1/1, 1/2, 2/1, 1/3, 3/2, 2/3, 3/1, 1/4, 4/3, 3/5, 5/2, 2/5, 5/3, 3/4, 4/1, ... Each denominator
is the next numerator. The numerators,
1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, 2, 5, 3, 4, ... (OEIS A002487),
are the terms of Stern's diatomic series
beginning at index 1. If this sequence is denoted by
, with
and
, then the
th fraction is
for positive integer
. Stern's
diatomic series is also known as the fusc function (Dijkstra 1982).