Exponential Search
Combines exponential growth with binary search. Especially useful for unbounded/infinite arrays.
Visualization
Interactive visualization for Exponential Search
Exponential Search
Sorted Array:
• Time: O(log n)
• Exponential growth then binary search
• Great for unbounded/infinite arrays
Interactive visualization with step-by-step execution
Implementation
1function exponentialSearch(arr: number[], target: number): number {
2 if (arr[0] === target) return 0;
3
4 let i = 1;
5 while (i < arr.length && arr[i] <= target) {
6 i *= 2;
7 }
8
9 const binarySearch = (left: number, right: number): number => {
10 while (left <= right) {
11 const mid = Math.floor((left + right) / 2);
12 if (arr[mid] === target) return mid;
13 if (arr[mid] < target) left = mid + 1;
14 else right = mid - 1;
15 }
16 return -1;
17 };
18
19 return binarySearch(i / 2, Math.min(i, arr.length - 1));
20}Deep Dive
Theoretical Foundation
Exponential search first finds a range where the target could lie by repeated doubling, then performs binary search within that range. Useful when the array size is unknown/unbounded.
Complexity
Time
O(1)
O(log n)
O(log n)
Space
O(1)
Applications
Industry Use
Search in infinite streams
Unbounded lists or file-like interfaces
External memory where size is not known
Use Cases
Related Algorithms
Binary Search
Binary Search is one of the most efficient searching algorithms with O(log n) time complexity. It works on sorted arrays by repeatedly dividing the search space in half, eliminating half of the remaining elements with each comparison. This divide-and-conquer approach makes it exponentially faster than linear search for large datasets.
Linear Search
Linear Search, also known as Sequential Search, is the simplest searching algorithm that checks each element in a list sequentially until the target element is found or the end is reached. Despite its O(n) time complexity, it's the only option for unsorted data and remains practical for small datasets or when simplicity is crucial.
Jump Search
Jump Search is an efficient algorithm for sorted arrays that combines the benefits of linear and binary search. Instead of checking every element (linear) or dividing the array (binary), it jumps ahead by fixed steps of √n and then performs linear search within the identified block. This approach achieves O(√n) time complexity, making it faster than linear search while being simpler than binary search for certain applications.
Interpolation Search
Interpolation Search is an improved variant of binary search specifically optimized for uniformly distributed sorted arrays. Instead of always checking the middle element, it estimates the target's position based on the target value relative to the range of values, similar to how humans search a phone book. Achieves O(log log n) average time for uniformly distributed data, significantly faster than binary search's O(log n).