Fast Rational Search via Stern-Brocot Tree
Connor Weyers, N. V. Vinodchandran
TL;DR
This work introduces a compressed Stern–Brocot tree traversal to solve rational search with comparison queries, achieving a worst-case bound of about 2.5849 log2 n and a lower bound of about 2.4189 log2 n. It leverages an exponential-binary search hybrid to determine run lengths in a run-length encoding of the Stern–Brocot path, and connects this approach to continued fractions. The authors extend the method to unbounded rational search and to finding best rational approximations of unknown real numbers, and contrast performance with the Kwek–Mehlhorn algorithm through experiments. The results show competitive behavior with clear theoretical bounds and practical applicability, though not yet optimal in the worst case and with some runtime trade-offs.
Abstract
We revisit the problem of rational search: given an unknown rational number $α= \frac{a}{b} \in (0,1)$ with $b \leq n$, the goal is to identify $α$ using comparison queries of the form ``$β\leq α$?''. The problem has been studied several decades ago and optimal query algorithms are known. We present a new algorithm for rational search based on a compressed traversal of the Stern--Brocot tree, which appeared to have been overlooked in the literature. This approach also naturally extends to two related problems that, to the best of our knowledge, have not been previously addressed: (i) unbounded rational search, where the bound $n$ is unknown, and (ii) computing the best (in a precise sense) rational approximation of an unknown real number using only comparison queries.
