Two Error Bounds of Imperfect Binary Search

Haoze Wu · DOI

Abstract

Suppose we know that an object is in a sorted table and we want to determine the index of that object. To achieve this goal we could perform a binary search. However, suppose it is time-consuming to determine the relative position of that object to any other objects in the table. In this scenario, we might want to resort to an incomplete solution: we could device an algorithm that quickly predicts the result of comparing two objects, and replace the actual comparison with this algorithm during a binary search. The question then is how far away are the results yielded by the imperfect binary search from the correct answers. We present two quick lemmas that answer this question.

Introduction

Binary search is a fundamental algorithm in computer science, prized for its ability to locate an element in a sorted list with $O(\log n)$ complexity. This efficiency, however, is predicated on the existence of a "perfect oracle"—a comparison function that always returns the correct relative ordering of elements.

In modern applications, comparisons are not always trivial. Whether comparing high-dimensional vectors in a database, evaluating preferences via a deep learning model, or processing complex multimedia files, the cost of a "perfect" comparison can be prohibitive. To optimize performance, developers often employ "noisy oracles": heuristic-based comparison functions that are significantly faster but possess a non-zero probability of error ($\epsilon$). This paper investigates the mathematical consequences of such a trade-off, specifically quantifying the expected distance between the search result and the true index.

The search process is modeled as a recursive reduction of the search space. At each step, the algorithm queries the noisy oracle to decide whether to move left or right.

  • With probability $1-\epsilon$, the oracle is correct, and the search space is halved toward the target.
  • With probability $\epsilon$, the oracle is incorrect, and the search moves away from the target.

Because binary search is a sequence of branching decisions, an error made early in the process—near the root of the decision tree—has a much larger impact than an error made near the leaves. A single mistake at the first step can displace the final result by at least $n/2$ positions.

Theoretical Bounds

The paper utilizes recurrence relations and geometric series to establish two primary bounds for the expected error.

Lemma 1: The Upper Bound

The first lemma provides a "worst-case" expected error, $a(n)$, assuming that any incorrect decision leads to the maximum possible remaining error within the sub-tree. $$a(n) \leq \epsilon \cdot n$$ This result is remarkably clean. It suggests that if an oracle has a 1% error rate ($\epsilon = 0.01$), the expected displacement in a list of 1,000 elements will be no more than 10 indices.

Lemma 2: Average Expected Error

The second lemma offers a more refined bound, $b(n)$, by accounting for the fact that subsequent steps—even if noisy—may still guide the search toward the "best possible" (albeit shifted) result within the incorrect branch. $$b(n) = \frac{\epsilon n(0.5 + \epsilon)}{1 + \epsilon}$$ This formula provides a tighter estimate for real-world scenarios where the search continues until the range is exhausted.

Key Insights

The most significant finding is the relationship between search time and error magnitude. While the time complexity remains logarithmic ($O(\log n)$), the expected error scales linearly ($O(n)$) with the size of the table. This linear scaling is a direct consequence of the hierarchical nature of binary search; the "penalty" for a wrong turn is proportional to the current size of the search space. If you know your $\epsilon$ and your $n$, you can immediately calculate the "cost" of speed in terms of accuracy.

Limitations and Future Directions

While these lemmas provide a robust theoretical foundation, they assume a constant error probability $\epsilon$. In practice, oracles are often "less certain" when elements are closer together, leading to non-uniform error rates. Furthermore, the current model does not account for:

  1. Error Correction: Strategies like backtracking or performing a local linear search at the conclusion of the binary search.
  2. Early Termination: Scenarios where the search stops immediately upon finding a match.

Conclusion

This work provides a vital "sanity check" for anyone implementing approximate search algorithms. By providing closed-form bounds for expected error, it allows engineers to rigorously evaluate whether the performance gains of a noisy oracle justify the resulting loss in precision.

Summary updated

BibTeX
@misc{wu2017two,
  author = {Haoze Wu},
  title = {{Two Error Bounds of Imperfect Binary Search}},
  year = {2017},
  eprint = {1711.01334},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1711.01334},
}
Figure