Searching

Exponential Search

Target:
Size:14
Visualizer is loading, please wait...
Execution Narrative
Step 1 of 8Start
Line 1
Starting Exponential Search for target 55 across 14 elements.
Comparisons0
Operations0

Overview & Concept

Exponential Search (Doubling Search) finds the range in which a target element resides by testing powers of 2 (1, 2, 4, 8, 16...) until an element greater than the target is found, then performs a Binary Search within that bounded range. It is especially useful for unbounded or infinite sorted arrays.

How It Works

Range Bounding: Starts at index 1 and repeatedly doubles i *= 2 until A[i] >= target or i >= n.

Subarray Binary Search: Executes binary search on the isolated sub-range [i/2, min(i, n - 1)].

O(log i) Time: Where i is the actual index position of the target element.

Step-by-Step Execution

1. Check Index 0If A[0] == target, return 0.
2. Find Upper Bound by DoublingSet bound = 1; while bound < n and A[bound] < target, bound *= 2.
3. Set Binary Search RangeConfigure low = bound / 2, high = Math.min(bound, n - 1).
4. Execute Binary SearchRun standard binary search on A[low..high].

Asymptotic Complexity Analysis

MetricBest CaseAverage CaseWorst CaseSpace Complexity
Complexity BoundO(1)O(log i)O(log i)O(1)
ExplanationOptimal input arrangement minimizing operations.Expected time for uniformly distributed randomized inputs.Adversarial degenerate conditions requiring full traversal.Auxiliary memory allocated beyond original input size.

Pseudocode & Invariants

Algorithm Logic
procedure exponentialSearch(A, target):
  if A[0] == target: return 0
  bound = 1
  while bound < n and A[bound] < target:
    bound *= 2
  return binarySearch(A, target, bound / 2, min(bound, n - 1))
Algorithmic Invariants
  • Range Bounding Invariant: Target resides strictly in [bound / 2, min(bound, n - 1)].
Correctness Guarantee: Invariants hold true prior to loop entry, are preserved during every iteration, and guarantee correct post-condition upon termination.

Advantages & Disadvantages

Key Advantages

  • •Excels when target is near the beginning of the array: runs in O(log i) time instead of O(log n).
  • •Works on unbounded or infinite arrays where the length n is not known beforehand.

Trade-offs & Limitations

  • •Requires sorted data.

Real-World Applications

Infinite Stream Lookups

Searching sorted continuous data streams with unknown total length.

Unbounded Disk Logs

Searching append-only sorted log files.

Decision Guide: When to Use

Ideal Scenarios

  • ✓When searching unbounded arrays or when target is likely near the start.

Consider Alternatives When

  • ✕When array size is known and target is uniformly distributed (standard Binary Search is simpler).

Compare trade-offs and complexity across complementary tools in AlgoViz.