Algorithms · Visualized
Exponential Search
Searching Algorithms
Six search strategies on a sorted array — from the obvious linear scan to log-time binary search and beyond.
Exponential Search finds a range where the target might exist by repeatedly doubling an index (1, 2, 4, 8, 16...) until it overshoots the target's value, then runs Binary Search within that bounded range. Time: O(log n) average, O(log n) worst; space: O(1).
Big-O: Binary O(log n), Linear O(n), Jump O(√n), Interpolation O(log log n) avg, Exponential O(log n).
Exponential Search
SearchingExponential Search finds a range where the target might exist by repeatedly doubling an index (1, 2, 4, 8, 16...) until it overshoots the target's value, then runs Binary Search within that bounded range. It's especially useful for unbounded or very large sorted arrays.
How Exponential Search Works
- Check if the first element is the target; if so, return it.
- Starting from index 1, keep doubling the index (1, 2, 4, 8, ...) as long as the value there is less than the target and you're still within bounds.
- Once the value at the current index is ≥ target (or you go out of bounds), you now have a range: from the previous index to the current one.
- Run Binary Search within that specific range to locate the exact position of the target.
- Return the result of the binary search (found index, or not found).
Exponential Search Worked Example
Input: {array: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21], target: 15}
Check index1 (3): 3<15, double to index2 (5): <15, double to index4 (9): <15, double to index8 (17): 17≥15, stop. Range is index4 to index8. Binary search within [9,11,13,15,17] finds 15 at index7.
def exponential_search(a, target):
if a[0] == target:
return 0
i = 1
n = len(a)
while i < n and a[i] <= target:
i *= 2
return binary_search(a, target, i // 2, min(i, n) - 1)Behind the Scenes Execution
Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.
Exponential Search Time & Space Complexity
When to Use Exponential Search
- Searching in unbounded or very large sorted arrays/streams where you don't know the size in advance.
- Slightly faster than plain binary search when the target is near the beginning of the array.
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Keep the momentum going
Step through a related structure, pattern or course — the ideas reinforce each other and stick faster.