In
number theory
Number theory is a branch of pure mathematics devoted primarily to the study of the integers and arithmetic functions. Number theorists study prime numbers as well as the properties of mathematical objects constructed from integers (for example ...
, the Stern–Brocot tree is an
infinite complete binary tree
In botany, a tree is a perennial plant with an elongated stem, or trunk, usually supporting branches and leaves. In some usages, the definition of a tree may be narrower, e.g., including only woody plants with secondary growth, only ...
in which the
vertices correspond
one-for-one to the
positive rational number
In mathematics, a rational number is a number that can be expressed as the quotient or fraction of two integers, a numerator and a non-zero denominator . For example, is a rational number, as is every integer (for example,
The set of all ...
s, whose values are ordered from the left to the right as in a
binary search tree
In computer science, a binary search tree (BST), also called an ordered or sorted binary tree, is a Rooted tree, rooted binary tree data structure with the key of each internal node being greater than all the keys in the respective node's left ...
.
The Stern–Brocot tree was introduced independently by and . Stern was a German number theorist; Brocot was a French
clockmaker who used the Stern–Brocot tree to design systems of gears with a
gear ratio close to some desired value by finding a ratio of
smooth numbers near that value.
The root of the Stern–Brocot tree corresponds to the number 1. The parent-child relation between numbers in the Stern–Brocot tree may be defined in terms of
simple continued fraction
A simple or regular continued fraction is a continued fraction with numerators all equal one, and denominators built from a sequence \ of integer numbers. The sequence can be finite or infinite, resulting in a finite (or terminated) continued fr ...
s or
mediants, and a path in the tree from the root to any other number provides a sequence of
approximations to with smaller
denominator
A fraction (from , "broken") represents a part of a whole or, more generally, any number of equal parts. When spoken in everyday English, a fraction describes how many parts of a certain size there are, for example, one-half, eight-fifths, thre ...
s than . Because the tree contains each positive rational number exactly once, a
breadth first search of the tree provides a method of listing all positive rationals that is closely related to
Farey sequences. The left subtree of the Stern–Brocot tree, containing the rational numbers in the range , is called the Farey tree.
Generating rule
Each vertex in the tree can be associated with a triple of fractions consisting of three fractions in the same row as the vertex, namely the fraction immediately to the left of the vertex, the fraction at the vertex itself, and the fraction immediately to the right of the vertex. (Refer to the figure above.) The left and right fractions do not correspond to vertices in the same row as the vertex, but rather to vertices in some preceding row. Each such fraction can be understood as labeling the region of the plane bounded by two infinite paths descending from the preceding vertex labeled by the same fraction. The second element of a triple will always be the mediant of the first and third elements. For example, the root is associated with
and its left and right descendents are associated with
and
The tree is generated by the following rule:
A tree of continued fractions
The relationship between parents and descendants can also be understood in terms of continued fractions. Every positive rational number may be expressed as a continued fraction of the form
where and are non-negative integers, and each subsequent coefficient is a positive integer. This representation is not unique because
but using this equivalence to replace every continued fraction ending with a one by a shorter continued fraction shows that every rational number has a unique representation in which the last coefficient is greater than one. Then, unless , the number has a parent in the Stern–Brocot tree given by the continued fraction expression
Equivalently this parent is formed by decreasing the denominator in the innermost term of the continued fraction by 1, and contracting with the previous term if the fraction becomes . For instance, the rational number has the continued fraction representation
so its parent in the Stern–Brocot tree is the number
Conversely each number in the Stern–Brocot tree has exactly two children: if