Skip to content

Exponential Backoff Search

Expand the search range exponentially until the target is bracketed, then refine within the range.

Exponential backoff search finds a target in a sorted or monotone structure by expanding the search interval geometrically. Instead of scanning linearly, it probes positions at increasing distances until it either finds the target or bounds it inside an interval. A secondary search then refines the result.

This method is useful when the size of the data is unknown, unbounded, or expensive to traverse fully.

Problem

Given a sorted sequence AA and a target xx, find an index ii such that

A[i]=x A[i] = x

or determine that no such index exists.

The length of AA may be unknown or very large.

Algorithm

Start from a small range. Double the range size until the target is less than or equal to the probed value. Then perform binary search inside the bounded interval.

exponential_backoff_search(A, x):
    if A[0] == x:
        return 0

    i = 1
    while i < length(A) and A[i] < x:
        i = i * 2

    left = i // 2
    right = min(i, length(A) - 1)

    return binary_search(A, x, left, right)

Example

Let

A=[2,4,7,10,15,21,30,45,60] A = [2, 4, 7, 10, 15, 21, 30, 45, 60]

and

x=21 x = 21

Probing phase:

stepindexvaluerelation
114< x
227< x
3415< x
4860≥ x

Now the target lies in the interval:

[4,8] [4, 8]

Binary search in that range returns index 55.

Correctness

The exponential phase guarantees that once A[i]xA[i] \ge x, the target must lie between i/2i/2 and ii if it exists. This follows from monotonic ordering. The subsequent binary search operates on a valid interval that contains all possible positions of xx.

Complexity

Let pp be the position of the target.

phasecost
exponential growthO(logp)O(\log p)
binary searchO(logp)O(\log p)

Total time:

O(logp) O(\log p)

Space complexity:

O(1) O(1)

When to Use

Use exponential backoff search when:

  • the sequence size is unknown
  • the data is accessed through an interface like a stream or API
  • random access exists but full length is unavailable
  • the target is expected near the beginning

This method appears in systems that probe latency, retry policies, and unbounded logs, where doubling reduces the number of probes.

Implementation

def exponential_backoff_search(a, x):
    if not a:
        return -1
    if a[0] == x:
        return 0

    i = 1
    n = len(a)

    while i < n and a[i] < x:
        i *= 2

    left = i // 2
    right = min(i, n - 1)

    while left <= right:
        mid = (left + right) // 2
        if a[mid] == x:
            return mid
        elif a[mid] < x:
            left = mid + 1
        else:
            right = mid - 1

    return -1
func ExponentialBackoffSearch(a []int, x int) int {
    n := len(a)
    if n == 0 {
        return -1
    }
    if a[0] == x {
        return 0
    }

    i := 1
    for i < n && a[i] < x {
        i *= 2
    }

    left := i / 2
    right := i
    if right >= n {
        right = n - 1
    }

    for left <= right {
        mid := (left + right) / 2
        if a[mid] == x {
            return mid
        } else if a[mid] < x {
            left = mid + 1
        } else {
            right = mid - 1
        }
    }

    return -1
}