Fibonacci Search Technique
The Fibonacci search technique is a comparison-based divide-and-conquer search algorithm introduced by David E. Ferguson that locates a target key in a sorted array in O(log n) time using Fibonacci-number interval partitioning through addition and subtraction alone.
Fibonacci search technique is a comparison-based divide-and-conquer algorithm within computation and algorithms for locating a target key x inside a sorted array A[0 .. n โ 1] (or finding the extremum of a discrete unimodal function) by successively partitioning the candidate search interval according to consecutive Fibonacci numbers. Originating in Jack Kiefer's 1953 minimax optimal sequential search for the maximum of a unimodal function and adapted to ordered table lookup by David E. Ferguson in 1960 in Communications of the ACM, the algorithm divides a search range of length Fk โ 1 into two unequal sub-intervals of lengths Fkโ1 โ 1 and Fkโ2 โ 1 around the split offset Fkโ1 โ 1 (or symmetrically Fkโ2 โ 1).
Unlike classical binary search, which computes midpoints via integer division by 2 or bitwise right shifts, Fibonacci search updates its probe offsets and step increments using only integer addition and subtraction (since Fkโ3 = Fkโ1 โ Fkโ2). Because the ratio of consecutive Fibonacci numbers converges to the golden ratio ฯ = (1 + โ5) / 2 โ 1.618034, each comparison shrinks the remaining candidate interval by a factor of either 1 / ฯ โ 0.618 or 1 / ฯ2 โ 0.382, completing in at most k โ 1 โ logฯ(โ5 ยท n) โ 1.4404 log2 n worst-case comparisons and approximately 1.055 log2 n average comparisons while requiring O(1) auxiliary workspace.
Mathematical Foundations and the Fibonacci Recurrence
Fibonacci Partitioning of an Interval of Size Fk โ 1
Define the standard Fibonacci sequence by the initial conditions F0 = 0, F1 = 1, and the second-order linear recurrence:
generating the sequence 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, โฆ. Observe that subtracting 1 from both sides of the Fibonacci recurrence and rearranging yields the precise interval-splitting identity:
Consequently, any contiguous sorted subarray containing exactly m = Fk โ 1 elements (for k โฅ 2) can be partitioned around a single interior pivot element into:
- A left sub-interval of length Fkโ2 โ 1 elements,
- The pivot element itself (1 element), and
- A right sub-interval of length Fkโ1 โ 1 elements.
Both resulting sub-intervals again have lengths of the precise form Fj โ 1 (specifically for j = k โ 2 and j = k โ 1), allowing the invariant to be maintained inductively all the way down to base intervals of length F1 โ 1 = 0 without ever rounding a fractional quotient.
Kiefer's Unimodal Minimax Optimality vs. Ferguson's Table Lookup
Historically, Fibonacci partitioning arose independently in two closely related settings:
- Kiefer's minimax unimodal optimization (1953): Given a real-valued function f that is unimodal (rising to a single peak and then falling) on an interval [a, b] and a fixed budget of N function evaluations, Jack Kiefer proved that placing the first two interior probes at fractional coordinates FNโ1 / FN+1 and FN / FN+1 is uniquely minimax optimal: after comparing f at those two points, one sub-interval is discarded while the surviving probe already sits at the precise Fibonacci split coordinate for the remaining N โ 1 evaluations, shrinking the uncertainty interval by a factor of 1 / FN+1.
- Ferguson's ordered-table search (1960): In a sorted array A[0 .. n โ 1] with a target key x, a single three-way comparison between x and A[i] (testing whether x < A[i], x = A[i], or x > A[i]) determines which side of index i contains x, so only one probe per step is required.
Step-by-Step Algorithm Using Addition and Subtraction Alone
Given a 0-indexed sorted array A[0 .. n โ 1] of length n โฅ 1 and a search key x, Fibonacci search avoids maintaining a lookup table of Fibonacci numbers by generating three rolling registers on the fly:
- Initialization (finding the smallest Fk โฅ n): Set Fkโ2 โ 0, Fkโ1 โ 1, and Fk โ Fkโ2 + Fkโ1 = 1. While Fk < n, advance the triple via addition: Fkโ2 โ Fkโ1, Fkโ1 โ Fk, and Fk โ Fkโ2 + Fkโ1. Initialize the eliminated prefix tracker offset โ โ1.
- Main elimination loop: While Fk > 1:
- Compute the candidate probe index i โ min(offset + Fkโ2, n โ 1) (clamping to n โ 1 handles array sizes n that are not of the form Fk โ 1, equivalent to padding A virtually with +โ up to length Fk โ 1).
- Case 1 (A[i] < x โ step right by one Fibonacci order): The left sub-interval of size Fkโ2 is eliminated. Advance offset โ i, and shift the Fibonacci registers down by one index using subtraction: Fk โ Fkโ1, Fkโ1 โ Fkโ2, and Fkโ2 โ Fk โ Fkโ1.
- Case 2 (A[i] > x โ step left by two Fibonacci orders): The right sub-interval of size Fkโ1 is eliminated, while offset remains unchanged. Shift the Fibonacci registers down by two indices using subtraction: Fk โ Fkโ2, Fkโ1 โ Fkโ1 โ Fkโ2, and Fkโ2 โ Fk โ Fkโ1.
- Case 3 (A[i] = x): Return index i.
- Final singleton check: If Fkโ1 = 1 and offset + 1 < n and A[offset + 1] = x, return offset + 1; otherwise return not found.
Notice that throughout Phase 2, every update to the Fibonacci triple uses only register moves and integer subtractionsโnever multiplication, division, or bit shifting.
| Search Algorithm | Split Ratio (Left : Right) | Index Arithmetic Required | Worst-Case Comparisons | Average Comparisons (Uniform) | Unimodal Function Adaptation |
|---|---|---|---|---|---|
| Binary Search | 1 : 1 (0.500 : 0.500) | Addition + division by 2 (or right shift) | โlog2 nโ + 1 | โ log2 n โ 1 | Requires 2 probes per step (dichotomous) |
| Fibonacci Search | 1/ฯ2 : 1/ฯ (0.382 : 0.618) | Addition and subtraction only | โ logฯ(โ5 ยท n) โ 1.44 log2 n | โ 1.055 log2 n | Minimax optimal (1 new probe per step) |
| Golden-Section Search | 1/ฯ2 : 1/ฯ (continuous) | Floating-point multiplication by ฯ โ 1 | Continuous convergence (0.618k) | 1.44 log2(1 / ฮต) | Standard continuous unimodal search |
| Exponential Search | Doubling + 1 : 1 binary | Bit shift + addition | 2โlog2 iโ + 2 | O(log i) | Bounded by target rank i |
| Jump Search | Fixed block m = โn | Addition of constant m | 2โn โ 1 | โn โ 0.5 | Sequential forward scan |
Asymptotic Complexity and Golden-Ratio Decision Tree Analysis
Worst-Case Path vs. Average-Case Path in the Fibonacci Decision Tree
By Binet's formula, the k-th Fibonacci number satisfies:
where ฯ = (1 + โ5) / 2 โ 1.6180339887 is the golden ratio and ฯ = (1 โ โ5) / 2 โ โ0.6180339887. Solving Fk โ n for the initial index k gives:
In the worst case, every comparison takes the larger branch (Case 1, where x > A[i]), which decrements the Fibonacci index from k to k โ 1 by only 1 unit per step. Thus the deepest root-to-leaf path in the Fibonacci decision tree has depth k โ 1 โ 1.4404 log2 n comparisons (roughly 44% more comparisons than binary search in the worst case).
In the average case under a uniform query distribution across all n = Fk โ 1 keys, however, the two branches are compensatory:
- With probability Fkโ1 / Fk โ 1 / ฯ โ 0.6180, the search takes the right branch, which performs 1 comparison and reduces the index by 1 (from k to k โ 1).
- With probability Fkโ2 / Fk โ 1 / ฯ2 โ 0.3820, the search takes the left branch, which performs 1 comparison but reduces the index by 2 units (from k to k โ 2).
Thus a single comparison reduces the Fibonacci index k by an expected ฮk = 1 ยท (1 / ฯ) + 2 ยท (1 / ฯ2) = (ฯ + 2) / ฯ2 = (3ฯ + 1) / (ฯ + 1) = (5 + โ5) / (2โ5) โ 1.381966 steps per comparison. Dividing the initial index k โ 1.44042 log2 n by the expected index reduction per step yields Knuth's precise average comparison count:
which is within 4.2% of the information-theoretic optimum log2 n achieved by perfectly balanced binary search.
Hardware Locality, Magnetic Drums, and Non-Uniform Access Costs
Donald Knuth analyzed an important physical asymmetry in Fibonacci search: while binary search always leaps across half the remaining interval (โm / 2โ), Fibonacci search moves the read head by Fkโ2 โ 0.382m in one direction and by Fkโ3 โ 0.236m in the other. On early rotating magnetic drum memories, magnetic tape units, and modern multi-level CPU caches or external-memory B-tree pages where seek latency increases monotonically with index distance, the average head displacement per probe in Fibonacci search is smaller than in binary search.
Furthermore, when evaluating a convex or unimodal objective function in numerical optimization (where each function evaluation is an expensive simulation or physical measurement and derivatives are unavailable), binary search cannot determine which half of [a, b] contains the minimum from a single midpoint sample; it must evaluate two closely spaced points around the midpoint at every step (requiring 2 log2(L / ฮต) evaluations). Kiefer's Fibonacci search reuses the surviving interior sample from the previous step as one of the two interior points of the new interval, reducing the required number of function evaluations to 1.44 log2(L / ฮต)โa 28% reduction in total oracle evaluations over dichotomous binary search.
Frequently Asked Questions
Why was avoiding division by 2 important when Ferguson published Fibonacci search in 1960?
Many first- and second-generation commercial computers of the late 1950s and early 1960s (such as decimal-coded business mainframes and minimal microcontroller architectures) lacked single-cycle arithmetic right-shift instructions on index registers and executed integer division via multi-cycle microcode subroutines. Because Fibonacci search computes every index offset using only addition and subtraction of pre-existing register values, its inner loop ran with lower instruction latency than midpoint division on those architectures.
What happens when the array length n is not equal to Fk โ 1?
The algorithm initializes Fk to the smallest Fibonacci number satisfying Fk โฅ n + 1 (or Fk โฅ n in the clamped variant) and clamps every candidate probe index i = min(offset + Fkโ2, n โ 1) to the last valid array index n โ 1. Clamping is mathematically equivalent to padding the array at indices n, n + 1, โฆ, Fk โ 2 with virtual sentinel keys equal to +โ without allocating any extra memory.
How does Fibonacci search relate to golden-section search?
Fibonacci search is the discrete, finite-horizon counterpart of golden-section search (introduced by Kiefer in 1953 and popularized by Avriel and Wilde in 1966). When the number of allowed evaluations N is fixed in advance on a discrete grid of Fk โ 1 points, Fibonacci ratios Fkโ1 / Fk achieve precise minimax optimality; when N is unspecified on a continuous real interval, taking the limit k โ โ replaces the rational ratio Fkโ1 / Fk with the constant golden ratio conjugate 1 / ฯ = (โ5 โ 1) / 2 โ 0.618034.
References
- Kiefer, J. (1953). "Sequential minimax search for a maximum." Proceedings of the American Mathematical Society, 4(3), 502โ506. https://doi.org/10.2307/2032161
- Ferguson, D. E. (1960). "Fibonaccian searching." Communications of the ACM, 3(12), 648. https://doi.org/10.1145/367487.367496
- Overholt, K. J. (1973). "Efficiency of the Fibonacci search method." BIT Numerical Mathematics, 13(1), 92โ96. https://doi.org/10.1007/BF01933527
- Knuth, D. E. (1998). The Art of Computer Programming, Volume 3: Sorting and Searching (2nd ed., Section 6.2.1: "Fibonaccian search," pp. 417โ422). Addison-Wesley. https://cs.stanford.edu/