On this page
Fractions arrive as a jumble: 3/7, 6/14 and 9/21 are the same number, and there is no obvious way to list them all. The Stern–Brocot tree fixes both problems with one rule you can do in your head.
What is the Stern–Brocot tree?
The Stern–Brocot tree is a binary tree made by starting with 0/1 and 1/0 and repeatedly inserting (m+m')/(n+n') between each pair of neighbouring fractions m/n and m'/n', as Wolfram MathWorld defines it.
It was found twice, independently: by the German number theorist Moritz Stern in 1858 and by the French clockmaker Achille Brocot in 1861. Brocot used it to design systems of gears with a ratio close to a target (Wikipedia, Stern–Brocot tree).
The fraction (a+c)/(b+d) is called the mediant of a/b and c/d. Build the tree row by row:
Start with 0/1 and 1/0 (think of 1/0 as infinity).
Their mediant is 1/1. That is the root.
Between 0/1 and 1/1 put 1/2; between 1/1 and 1/0 put 2/1.
The next row is 1/3, 2/3, 3/2, 3/1, then 1/4, 2/5, 3/5, 3/4, 4/3, 5/3, 5/2, 4/1.
Why does every fraction appear exactly once?
Every positive rational number appears exactly once in the tree (Wikipedia). It is a search tree: everything left of a fraction is smaller, everything right is larger, so nothing repeats.
Why lowest terms? Neighbours a/b and c/d in any row satisfy bc − ad = 1. That holds for 0/1 and 1/0, and it passes to each fraction and its mediant: (b+d)c − (a+c)d = 1. So a+c and b+d share no factor, and you never meet 2/4.
How do you find 3/7 in the Stern–Brocot tree?
Play a guessing game. Start at the root, compare, and keep the two bounds you are between.
At 1/1: 3/7 is smaller, go L. Bounds 0/1 and 1/1, so the next node is 1/2.
At 1/2: smaller, go L. Bounds 0/1 and 1/2; next node 1/3.
At 1/3: larger, go R. Bounds 1/3 and 1/2; next node 2/5.
At 2/5: larger, go R. Bounds 2/5 and 1/2; their mediant is 3/7. Found.
So 3/7 has the address LLRR, and no other fraction shares it.
How is the tree linked to continued fractions?
Write 3/7 as a continued fraction: 7/3 = 2 + 1/3, so 3/7 = [0; 2, 3]. Now look at the path: zero Rs, then two Ls, then two Rs. The run lengths are the continued fraction terms, with the last one cut by 1. Try 7/5 = [1; 2, 2]: the path is R, LL, R.
The depth tells you the same thing. A fraction whose continued fraction terms add up to s sits s − 1 steps below the root (Wikipedia). For 3/7 the terms add to 0 + 2 + 3 = 5, and it sits at depth 4.
New to continued fractions? Our explainer on continued fractions, the golden ratio, √2 and π starts from scratch. The Farey sequence and its mediants is a close cousin: each Farey sequence is a pruned subtree of the Stern–Brocot tree (MathWorld).
What is the Calkin–Wilf tree?
In 2000, Neil Calkin and Herbert Wilf published a short paper, Recounting the Rationals, in The American Mathematical Monthly (volume 107, pages 360–363). Their tree has a simpler rule: the children of a/b are a/(a+b) on the left and (a+b)/b on the right (Wikipedia, Calkin–Wilf tree).
To find 3/7, climb up: if the top is smaller, the parent is a/(b−a); if larger, (a−b)/b. So 3/7 → 3/4 → 3/1 → 2/1 → 1/1, and from the root the path is RRLL, the Stern–Brocot path backwards. Both trees hold the same fractions on each level, but only Stern–Brocot is a search tree (same source).
Read row by row, the Calkin–Wilf tree gives 1/1, 1/2, 2/1, 1/3, 3/2, 2/3, 3/1, and each denominator is the next numerator (Wikipedia): every positive fraction in one list, none repeated.
A 15-minute practice plan
Draw four rows of the Stern–Brocot tree from memory, using only mediants.
Find the address of 5/8. (Answer: LRLR, matching 5/8 = [0; 1, 1, 1, 2].)
Go backwards: which fraction sits at RLLR? (Answer: 7/5.)
Find 5/8 in the Calkin–Wilf tree by climbing up, and check the path is reversed.
To revise mediants and continued fractions from the ground up, the Fermi Concept Library gives every concept in mathematics its own lesson. Next, try writing a fraction as a sum of unit fractions.



