Chapter 4 · Simulation

Exponential Search

← Chapter 4
PhaseReady
bound–
lo–
hi–
mid–
Probes0

    Probe sequence: –

    Exponential Search

    First the search bound is expanded exponentially, then binary search runs inside the range that was found.

    How to use

    • Enter a target; press Search to animate the whole search or Step to advance one comparison at a time.
    • Reset clears the run; New array generates a new sorted array of 20 distinct values.
    • The red labels above the cells show the probed bounds 1, 2, 4, 8, 16; the blue bar is the current binary search range [lo, hi].

    Algorithm

    1. If A[0] equals the target, stop.
    2. Start with bound = 1; while bound < n and A[bound] < target, double bound.
    3. If the target is in the array, it lies in A[bound/2 … min(bound, n − 1)]; run binary search there.

    Complexity

    If the target is at position i, the doubling phase takes about log₂ i steps and the binary search works on a range of size about i, so the total time is O(log i) ≤ O(log n) with O(1) extra memory. It is useful for sorted lists of unknown or very large size when the target is near the front.