Overview & Concept
Interpolation Search is an improvement over Binary Search for sorted arrays where values are uniformly distributed. Instead of always checking the middle, it estimates the target position using linear interpolation formula: pos = low + ⌊((target - A[low]) / (A[high] - A[low])) × (high - low)⌋, achieving average O(log log n) time.
How It Works
Proportional Estimation: Models real-world phonebook lookups (looking up a name starting with "Z" near the end).
Interpolation Formula: Calculates probe index based on value magnitude relative to range bounds.
O(log log n) Average Time: For uniformly distributed values, search interval shrinks super-exponentially.
Step-by-Step Execution
Asymptotic Complexity Analysis
| Metric | Best Case | Average Case | Worst Case | Space Complexity |
|---|---|---|---|---|
| Complexity Bound | O(1) | O(log log n) | O(n) | O(1) |
| Explanation | Optimal 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
procedure interpolationSearch(A, target):
low = 0; high = n - 1
while low <= high and target in [A[low]..A[high]]:
pos = low + floor(((target - A[low]) / (A[high] - A[low])) * (high - low))
if A[pos] == target: return pos
else if A[pos] < target: low = pos + 1
else: high = pos - 1
return -1- Interpolation Invariant: Target value resides within [A[low], A[high]] at each iteration.
Advantages & Disadvantages
Key Advantages
- •Average-case O(log log n) time on uniformly distributed data (faster than binary search).
- •Minimizes total memory access probes by calculating expected target location directly.
Trade-offs & Limitations
- •Degenerates to O(n) worst-case time on exponentially distributed or heavily skewed data.
- •More complex arithmetic operations (division and multiplication) per probe.
Real-World Applications
Uniformly Distributed Telemetry Indexes
Searching time-series timestamps sampled at regular fixed intervals.
Decision Guide: When to Use
Ideal Scenarios
- ✓When keys are sorted AND known to follow a uniform probability distribution.
Consider Alternatives When
- ✕When data has severe clustering or non-linear distributions (use Binary Search).
Explore Related Algorithms
Compare trade-offs and complexity across complementary tools in AlgoViz.