Exponential Search visualization

Double a bound until it passes the target, then binary search inside that range.

Great for unbounded or very long lists: the doubling phase finds a range of size ~2i containing the target in O(log i) steps, then binary search finishes the job.

Complexity

Time: best O(1), average O(log i), worst O(log n). Space: O(1). Difficulty: Intermediate.

Pseudocode

procedure exponentialSearch(A, target):
  if A[0] = target: return 0
  bound ← 1
  while bound < n and A[bound] < target: bound ← bound · 2
  return binarySearch(A, bound/2, min(bound, n−1))

More searching algorithms