Stern-Brocot tree (source code)

= Stern-Brocot tree
{c}

= Stern-Brocot
{c}
{synonym}

A <binary tree> enumerating every positive <reduced fraction> exactly once. Begin with boundary fractions $0/1$ and $1/0$; between neighboring fractions $a/b<c/d$, insert their mediant $(a+c)/(b+d)$ and recurse into the two new intervals. The <determinant> relation $bc-ad=1$ is preserved, and the new <denominator> is $b+d$.