See Algorithms
SEE ALGORITHMS

Exponential Search Visualization

Exponential Search locates a target in a sorted array in two phases: first, it doubles an index bound (1, 2, 4, 8, ...) until it brackets the target; second, it runs Binary Search within that narrowed range. If the target resides at position i, Exponential Search finds it in O(log i) time — making it faster than standard Binary Search whenever the target lies close to the front of a massive array.


Pseudocode

if arr[0] == target: return 0
bound = 1
while bound < n and arr[bound] <= target:
    bound = bound * 2
low = bound / 2
high = min(bound, n - 1)
while low <= high:
    mid = floor((low + high) / 2)
    if arr[mid] == target: return mid
    else if arr[mid] < target: low = mid + 1
    else: high = mid - 1
return -1

Visualizer


Exponential boundComparing (mid)EliminatedFound

Control speed:


Key Properties

  • Safe Upper Clamping: Clamping high protects against reading past the end of finite arrays when doubling overshoots n.
  • Unbounded Search: Because the search starts from index 0 and doubles outward, it never needs to know the total length of the array ahead of time.
  • Cache Friendliness: Probing exponentially from the start keeps early accesses within hot lower-index cache pages before jumping farther out.

When to Use

Exponential Search shines on unbounded or infinite sorted sequences (such as streamed sorted logs or lazy generators where n is unknown) and on very large arrays where queries are skewed toward the beginning. In those cases, O(log i) comparisons can be dramatically smaller than O(log n).

In practice, Exponential Search is a core building block of Timsort (the default sorting algorithm in Python and Java for objects), where "galloping mode" skips ahead exponentially when one sorted run repeatedly wins during merging.

Time & Space Complexity

Metric / Operation
Complexity
Description
Best CaseO(1)When the target is located at index 0.
Average CaseO(log i)Where i is the index of the target: doubling finds the range in O(log i) and Binary Search runs on a slice of size i/2.
Worst CaseO(log n)When the target sits near the end of the array or is absent, requiring O(log n) steps across both phases.
Space ComplexityO(1)Iterative Exponential Search uses constant space for range boundaries.

Common Interview Questions

What makes Exponential Search ideal for unbounded or very large sorted arrays?

Exponential Search discovers an upper bound by doubling the index in O(log i) steps (where i is the target's position) without needing the array size up front, then runs Binary Search within [bound/2, bound].

Why does Exponential Search check index 0 separately before starting with bound = 1?

The bracketing loop advances by doubling bound *= 2; if bound started at 0, doubling would stay at 0 forever. Checking arr[0] first handles index 0 cleanly and lets doubling proceed further.


💬  Discussion

to join the discussion


Curious to Learn More?

Hand-picked resources to deepen your understanding


Learn DSA on Udemy
Learn DSA on Udemy
As an Udemy Associate, I earn from qualifying purchases.

© 2025 See Algorithms. Code licensed under MIT, content under CC BY-NC 4.0