Back to All Algorithms
Exponential Search
Category: Searching | Time: O(log n) | Space: O(1)
Visualization
Visual representation of the data structure
About Exponential Search

An algorithm used for searching in sorted, unbounded arrays. It involves two steps: first finding a range where the element could be, and then performing a binary search within that range.

Code Editor
The code is for reference. Editing it won't affect the visualization.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Variable State
{
  "arr": "[2, 3, 4, 10, 40]",
  "target": 10,
  "n": 5
}
Exponential Search: How It Works
Last updated October 28, 2026

Overview

Exponential Search, also called galloping or doubling search, first finds a range that must contain the target and then runs binary search inside that range. It checks indices 1, 2, 4, 8, 16, … until it finds an element larger than the target or runs off the end.

Because the range doubles each time, finding it takes O(log i) steps, where i is the position of the target. That makes it better than plain binary search when the target is near the start, and it works even when the array length is unknown or unbounded.

In the default example (2, 3, 4, 10, 40, target 10), index 0 does not match, so i grows 1 → 2 → 4. At index 4 the value 40 is larger than 10, so binary search runs on indices 2..4 and finds 10 at index 3.

Step by step

  1. If arr[0] is the target, return 0.
  2. Set i = 1; while i < n and arr[i] <= target, double i.
  3. Run binary search on the range floor(i / 2) .. min(i, n - 1).
  4. Return the binary search result.

Complexity

CaseCostWhy
Best caseO(1)The target is at index 0.
Average caseO(log i)i is the target position; both phases are logarithmic in i.
Worst caseO(log n)Target near the end.
Extra spaceO(1)Iterative binary search phase.

When to use it

  • Unbounded or very large sorted sequences, such as an infinite stream or an API without a length.
  • When targets are usually near the beginning.
  • The galloping step in Tim Sort's merge uses this same idea.

Common mistakes

  • Starting at i = 0 means doubling never moves (0 × 2 = 0); start at 1.
  • The binary-search bounds must be clamped to n - 1.
  • It still requires sorted input.
Worked Example: Exponential Search Dry Run
Generated from the same trace that drives the visualizer above, using the default input.

A dry run is the best way to check your understanding of Exponential Search: follow each row, predict the next one, and compare. The run below takes 13 steps in total. Steps that only re-print loop counters are left out so the decisions stand out. The Line column refers to the line numbers in the code listing above.

Input
2,3,4,10,40
Target
10
Result
return value = 3
StepLineArrayWhat happens
11[2, 3, 4, 10, 40]target = 10, n = 5
22[2, 3, 4, 10, 40]condition = 2 == 10
46[2, 3, 4, 10, 40]i = 1, n = 5, condition = 1 < 5 && 3 <= 10
66[2, 3, 4, 10, 40]i = 2, n = 5, condition = 2 < 5 && 4 <= 10
86[2, 3, 4, 10, 40]i = 4, n = 5, condition = 4 < 5 && 40 <= 10
910[2, 3, 4, 10, 40]from = 2, to = 4, status = Calling Binary Search
1016[2, 3, 4, 10, 40]low = 2, high = 4, condition = 2 <= 4
1218[2, 3, 4, 10, 40]mid = 3, arr[mid] = 10, target = 10, condition = 10 === 10
1319[2, 3, 4, 10, 40]return value = 3
Frequently Asked Questions
About Exponential Search

What is Exponential Search?

Exponential Search is an algorithm used to find an element in a sorted, unbounded or infinite array. It can also be more efficient than Binary Search on bounded arrays when the target element is near the beginning.

How does Exponential Search work?

It works in two steps. First, it finds a range where the element could be present. It starts with a sub-array of size 1, compares the last element with the target, and then doubles the sub-array size until the last element is greater than the target. Second, it performs a Binary Search within that final identified range.

What is the time complexity?

The time complexity is O(log n). Finding the range takes O(log i) where i is the index of the target element, and the subsequent binary search takes O(log i). In the worst case, i can be n, so the complexity is O(log n).

Why is it useful for unbounded arrays?

It's useful for unbounded (or infinite) arrays because it doesn't need to know the size of the array to start. It finds a suitable range first and then performs a bounded binary search.

What is the space complexity?

If the final binary search is iterative, the space complexity is O(1). If it's recursive, it's O(log n) for the call stack.

When is it faster than Binary Search on a bounded array?

It can be faster if the target element is located near the beginning of the array. Binary Search always starts at the middle, while Exponential Search starts its range-finding at the beginning, so it can find a small range and finish its binary search much faster.

Is a sorted array required?

Yes, the array must be sorted for both the range-finding step and the final binary search to work correctly.

How does it differ from Interpolation Search?

Exponential Search's strategy is based on finding a range by doubling, while Interpolation Search's strategy is based on probing a likely position using a formula. Exponential Search does not require uniformly distributed data.

Can it be implemented without recursion?

Yes, the final binary search step can be implemented iteratively to avoid recursion and reduce space complexity.

What is another name for Exponential Search?

It is also sometimes known as Galloping Search or Doubling Search.

Where can I learn more?

You can find a more detailed explanation on GeeksforGeeks.