Interpolation Search
Interpolation search is a numerical array search algorithm introduced by Peterson that estimates the target index via linear value interpolation, achieving O(log log n) expected probes on uniformly distributed sorted keys.
Interpolation search is a value-aware search algorithm within computation and algorithms for locating a numerical key x inside a sorted array A[0 .. n โ 1] by estimating the target's array position proportionally from the boundary key values A[low] and A[high]. First described by W. Wesley Peterson in 1957 in the context of open-addressed hash tables and sequential index files, and rigorously analyzed by Andrew Chi-Chih Yao and F. Frances Yao (1976) and by Yehoshua Perl, Alon Itai, and Haim Avni (1978), interpolation search models the intuitive strategy used when looking up a name in a telephone directory: rather than opening the book to the midpoint as in divide-and-conquer binary search, one probes near the front for a surname beginning with "B" and near the back for "W".
When the n sorted keys are drawn independently from a uniform distribution (or any smooth distribution transformed via its cumulative distribution function), each linear interpolation probe squares the relative width of the remaining uncertainty interval, reducing the expected number of array probes from โlog2 nโ + 1 down to log2 log2 n + O(1)โan asymptotic average-case complexity of O(log log n). Conversely, on adversarially skewed or geometrically growing keys where linear interpolation repeatedly steps by a single index, unmodified interpolation search degrades to O(n) worst-case time unless safeguarded by hybrid alternation with binary or exponential search or by Dan E. Willard's O(โ(log n)) SantoroโSidney interpolation-binary scheme.
Linear Interpolation Probe Formula and Execution
Proportional Position Estimation
Let A[0 .. n โ 1] be a sorted array of distinct numerical keys and let [low, high] denote the current active search interval satisfying A[low] โค x โค A[high]. Under the hypothesis that key values grow approximately linearly with array index across [low, high], the fraction of the index interval (pos โ low) / (high โ low) should match the fraction of the key interval (x โ A[low]) / (A[high] โ A[low]). Solving for the integer probe coordinate pos yields the linear interpolation probe formula:
At each iteration, the algorithm checks that low โค high and A[low] โค x โค A[high] ( guarding against division by zero when A[low] = A[high]):
- Evaluate pos using 64-bit or 128-bit integer arithmetic (or floating-point division) so the product (x โ A[low]) ยท (high โ low) cannot overflow.
- Compare the target x against A[pos]:
- If A[pos] = x, return pos.
- If A[pos] < x, narrow the search interval to the upper subrange by setting low โ pos + 1.
- If A[pos] > x, narrow the search interval to the lower subrange by setting high โ pos โ 1.
Order Statistics of Uniform Keys and Conditional Variance
Why does linear interpolation shrink the active interval from size m = high โ low + 1 to size O(โm) per probe on average? Suppose m keys are drawn independently and uniformly from a continuous interval [a, b] and sorted in ascending order. By the classical theory of Beta order statistics, conditioned on the endpoint values A[low] = a and A[high] = b, the number of keys K falling below the target value x follows a binomial distribution Bin(m โ 2, p) where p = (x โ a) / (b โ a) is the normalized interpolation ratio.
A binomial random variable K ~ Bin(N, p) has mean ฮผ = Np (which is precisely the index offset selected by the interpolation probe pos โ low) and standard deviation:
By Chebyshev's inequality and Chernoff tail bounds, the true rank of x inside [low, high] deviates from the interpolated probe index pos by only O(โm) indices in expectation. Consequently, when the next probe (or a secondary bracket check) isolates the subinterval containing x, the effective number of candidate elements drops from m to approximately โm.
Asymptotic Average-Case and Worst-Case Complexity
Doubly Logarithmic Convergence and the YaoโYao Lower Bound
Because each interpolation step maps an uncertainty scale of mk elements to an expected scale of mk+1 โ โmk = mk1/2, after k successive probes an initial array of size n contracts to expected size:
Reducing the active interval down to a constant number of elements (mk โค 2) requires n2โk โค 2, or 2โk log2 n โค 1. Taking base-2 logarithms a second time gives:
Perl, Itai, and Avni (1978) proved via Martingale potential functions on the conditional variance that the expected number of probes for interpolation search on n independent uniform keys is at most log2 log2 n + 3. In a companion theoretical landmark, Andrew Yao and Frances Yao (1976) proved that any search algorithm using arbitrary arithmetic functions of the probed keys must perform at least log2 log2 n + O(1) probes on average over uniform keys, establishing that simple linear interpolation is asymptotically optimal. For an array of n = 232 โ 4.29 ร 109 uniform 32-bit integers, log2 log2(232) = 5, so interpolation search inspects roughly 5 to 6 array slots compared with 32 probes for binary search.
| Search Strategy | Average Probes (Uniform Keys) | Worst-Case Probes (Adversarial Skew) | Arithmetic Cost per Probe | Key Requirement |
|---|---|---|---|---|
| Binary Search | โlog2 nโ | โlog2 nโ + 1 | 1 shift + 1 addition | Total order only |
| Exponential Search | 2โlog2 iโ + 1 | 2โlog2 nโ + 2 | 1 shift | Total order only |
| Pure Interpolation Search (1957) | log2 log2 n + O(1) | n | 1 multiplication + 1 division | Numerical metric keys |
| Quadratic Binary Search (1976) | โ 2.4 log2 log2 n | O(โn) (or O(log n) with doubling) | 1 division + โm steps | Numerical metric keys |
| SantoroโSidney / Willard Hybrid (1985) | log2 log2 n + O(1) | O(โ(log n)) or O(log n) | Interleaved interpolation + binary | Numerical metric keys |
| Three-Point / TIP Interpolation (2019) | O(log log n) on smooth CDFs | O(log n) with fallback | Rational/quadratic fit | Smooth non-uniform keys |
Adversarial Skew and Worst-Case O(n) Degradation
When the sorted array violates uniformityโfor example, when keys follow a geometric progression A[j] = 10j (1, 10, 100, โฆ, 10nโ1) and the target is x = 10nโ2โthe denominator A[high] โ A[low] = 10nโ1 โ 1 is dominated by the final element. For every target smaller than 10nโ2, the ratio (x โ A[low]) / (A[high] โ A[low]) is less than 0.01, so for any array of size n โค 100 the formula evaluates to pos = low + 0 = low. Setting low โ pos + 1 advances the left boundary by only a single element per step, degrading interpolation search to n โ 1 probesโequivalent to linear search.
Hybrid Safeguards and Modern Hardware Considerations
Quadratic Binary Search and Interpolation-Exponential Hybrids
To eliminate the O(n) worst case while retaining O(log log n) average performance on uniform keys, two classical modifications are used:
- Quadratic Binary Search (Gonnet, Rogers, and George, 1980) and Interpolation-Exponential Search: After computing the interpolated probe pos and observing, say, A[pos] < x, instead of re-interpolating across the entire remaining suffix [pos + 1, high], the algorithm walks outward from pos in multiples of โm (or in powers of two pos + 20โm, pos + 21โm, โฆ) to bracket x within a narrow window before recursing.
- SantoroโSidney and Willard's ฮธ-Search (1985): Nicola Santoro and Jeffrey B. Sidney (1985) and Dan E. Willard (1985) interleaved each interpolation probe with a binary probe (or a guarded fraction probe inside [low + ฮธm, high โ ฮธm]), proving that the worst-case number of probes is bounded by O(log n) (or O(โ(log n)) under Willard's adaptive fraction schedule) on arbitrary key distributions while still finishing in O(log log n) expected probes on uniform data.
Division Latency vs. Memory-Hierarchy Latency and Learned Indexes
On modern superscalar CPUs, a 64-bit integer division (idiv) requires 15 to 40 clock cycles, whereas binary search uses a single 1-cycle right shift (shr). For tiny arrays that fit inside the L1 cache (n โค 256), binary search often finishes faster in wall-clock time despite doing more probes. Once n exceeds the L3 cache (n โฅ 107) or resides on SSD/NVMe storage alongside structures like the B-tree, van Emde Boas tree, or y-fast trie, each random probe incurs a 60โ100 ns DRAM miss or microsecond I/O stall, and eliminating 80% of memory probes via interpolation (such as Three-Point Interpolation Search, TIP, or piecewise linear learned indexes) delivers substantial throughput gains.
Frequently Asked Questions
How does interpolation search avoid integer overflow when computing the probe index?
Because the product (x โ A[low]) ยท (high โ low) multiplies a key difference by an array length, both of which may be 32-bit or 64-bit integers, production implementations either promote both operands to a wider integer type (such as 128-bit integer arithmetic for 64-bit keys) before dividing by (A[high] โ A[low]), or compute the normalized ratio as an IEEE 754 double-precision float in [0.0, 1.0] and multiply by (high โ low) before clamping the result to [low, high].
Can interpolation search be applied to non-uniform distributions or lexicographic strings?
Yes, provided an inexpensive monotonic transformation maps the keys to an approximately uniform space. If keys follow a known cumulative distribution function F(x), applying the probability integral transform u = F(x) converts the keys into uniform [0, 1] variates before interpolating. For fixed-prefix ASCII or UTF-8 strings, interpreting the first 8 bytes of each string as a big-endian 64-bit integer enables numerical interpolation across lexicographically sorted string tables, though common prefixes require stripping shared leading bytes at each narrowing step.
Why must low be updated to pos + 1 rather than pos when A[pos] < x?
When x โ A[low] is small relative to A[high] โ A[low], the floor operation in the interpolation formula frequently rounds the offset down to 0, yielding pos = low. If the algorithm set low โ pos instead of low โ pos + 1 after confirming A[pos] < x, the next iteration would recompute the identical probe pos = low and enter an infinite loop. Advancing low โ pos + 1 and high โ pos โ 1 guarantees that every unsuccessful probe eliminates at least one element and that the search terminates in finite steps.
References
- Peterson, W. W. (1957). "Addressing for random-access storage." IBM Journal of Research and Development, 1(2), 130โ146. https://doi.org/10.1147/rd.12.0130
- Yao, A. C.-C., & Yao, F. F. (1976). "The complexity of searching an ordered random table." In 17th Annual Symposium on Foundations of Computer Science (SFCS 1976), 173โ177. https://doi.org/10.1109/SFCS.1976.32
- Perl, Y., Itai, A., & Avni, H. (1978). "Interpolation searchโa log log N search." Communications of the ACM, 21(7), 550โ553. https://doi.org/10.1145/359545.359557
- Gonnet, G. H., Rogers, L. D., & George, J. A. (1980). "An algorithmic and complexity analysis of interpolation search." Acta Informatica, 13(1), 39โ52. https://doi.org/10.1007/BF00288534
- Willard, D. E. (1985). "Searching unindexed and nonuniformly generated files in log log N time." SIAM Journal on Computing, 14(4), 1013โ1029. https://doi.org/10.1137/0214071