Efficient Search for Rationals

It is well-known that an integer x not greater than M, can be determined exactly by O(log .4Q queries of the form “is x < k?” In this paper we address I’he same problem when x is known to be a positive rational fraction, with enumerator and denominator bounded by M. We show that x can be determined exactly by O(log M) queries of the form ‘79 x G p/q?” where p, q G M Naturally, there is a trivial algorithm for doing so, which uses binary search on the set of S2(M2) such fractions; however, this algor:ithm has a preprocessing phase that requires n@f’) time. Our algorithm requires, besides the O(log M) queries, only O(logM) other arithmetic operations and comparisons of integers of size up to 2M. Our proof is based on Farey series [HW] . Naturally, our bound is asymptotically optimal, since it takes log M queries just to distinguish among