← All Tools

Stern–Brocot Tree Explorer

The Stern–Brocot tree is the binary tree of every positive rational in lowest terms, each appearing exactly once. Start with the boundary 01 and 10. At each step the tree inserts the mediant a + cb + d between the two current neighbours — and a mediant is automatically the fraction with the smallest denominator that lies strictly between them. Type any positive real and this tool walks the tree, giving you the L/R path, every convergent, and the sharpest rational approximation for a chosen denominator ceiling.

Best approximation

Convergents from the continued fraction

kakpk/qkvalueerror|x − p/q|·q²
The |x − p/q| · q² column is Hurwitz’ test: an infinite subsequence of convergents keeps it below 1 / √5 ≈ 0.447 for irrational x.

Path down the tree (mediant sequence)

Why the mediant is optimal

A fraction pq is a best rational approximation of the second kind to x if no other p′q′ with q′ ≤ q satisfies |q′x − p′| < |qx − p|. Every best approximation of the second kind (with a mild exception at the head) is a convergent of x’s continued-fraction expansion — and every convergent is a node of the Stern–Brocot tree encountered along the descent toward x. That’s why the R/L path you see below is really the continued fraction in disguise: each run of L’s (or R’s) of length ak corresponds to the partial quotient ak.