Exponential Search - Finding the Range First

Published on Thursday, July 16, 2026

Exponential Search is a two-phase algorithm: it first finds the range where the target must be (by exponentially doubling an index), then applies binary search within that range. The result is an algorithm particularly well-suited to unbounded arrays — sequences where you don’t know the size upfront.

A Brief History

Exponential search was described by Jon Bentley and Andrew Chi-Chih Yao in their 1976 paper “An Almost Optimal Algorithm for Unbounded Searching” (Information Processing Letters). It was developed to handle the problem of searching in sorted sequences of unknown or infinite length — a scenario that breaks traditional binary search (which needs to know high = array.length - 1 upfront). The algorithm has since become a standard technique in competitive programming and systems that work with sorted streams or very large files.

How It Works

Exponential search runs in two clean phases:

Phase 1 — Find the range:

  1. Start with index i = 1.
  2. While i < array.length and arr[i] <= target, double i (set i = i * 2).
  3. The target, if present, lies in the range [i/2, min(i, array.length - 1)].

Phase 2 — Binary search within the range: 4. Run binary search on arr[i/2 ... min(i, n-1)]. 5. Return the result.

The doubling in phase 1 means you reach a range of size 2k2^k after kk steps — which is at most log⁡2(target index)\log_2(\text{target index}) steps. Then binary search within that range of size 2k2^k takes another kk steps. Total: O(2k)=O(log⁡i)O(2k) = O(\log i) where ii is the target’s index.

Time Complexity

Case Complexity Scenario
Best O(1)O(1) Target is at index 1 (first check)
Average O(log⁡n)O(\log n) Target found after range + binary search
Worst O(log⁡n)O(\log n) Target near end or not present

More precisely, the complexity is O(log⁡i)O(\log i) where ii is the index of the target — which means exponential search is better than binary search when the target is near the beginning of the array. A target at index 8 takes only 3 doublings + 3 binary search steps, vs binary search on 1,000,000 elements taking 20 steps.

Space Complexity

Use the iterative variant for constant space.

Advantages and Disadvantages

Advantages:

  • Works on unbounded/infinite sorted sequences — you never need to know the total size
  • Better than binary search when the target is near the start — O(log⁡i)O(\log i) vs O(log⁡n)O(\log n)
  • Useful when data is sorted but accessed sequentially (streams, very large files)
  • Naturally adapts to where the target is, rather than always bisecting the full range

Disadvantages:

  • Requires a sorted array, like all efficient search algorithms
  • Slightly more complex than binary search — two phases instead of one
  • Overhead of the doubling phase is wasted if the target is far from the start
  • For typical in-memory arrays with known length, binary search is simpler and equally fast

Exponential search shines in specific scenarios:

  • Unbounded or infinite sorted arrays — searching in a sorted stream or infinite sequence where you can’t set high = n - 1
  • Very large sorted files — when you don’t want to seek to the end just to find the length
  • Target expected near the beginning — if your access patterns skew toward early elements, exponential search is provably faster than binary search
  • When binary search fails due to unknown bounds — drop-in replacement that handles the “I don’t know the size” problem elegantly

In conclusion, exponential search is a clever solution to a real problem: searching sorted data when you don’t know how much of it exists. The doubling phase elegantly narrows down the search space without ever needing to know the total size. For bounded in-memory arrays, binary search is simpler — but when your data is a stream, a file, or conceptually infinite, exponential search is exactly the right tool.


lightning-logo
Unleash the power of performance by comparing your code. Performance. Unbound.