โ† Wiki Index / Computation & Algorithms / Fibonacci Search Technique
๐Ÿ’ป Computation & Algorithms

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:

Fk = Fkโˆ’1 + Fkโˆ’2 for all k โ‰ฅ 2

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:

(Fkโˆ’2 โˆ’ 1) + 1 + (Fkโˆ’1 โˆ’ 1) = (Fkโˆ’2 + Fkโˆ’1) โˆ’ 1 = Fk โˆ’ 1

Consequently, any contiguous sorted subarray containing exactly m = Fk โˆ’ 1 elements (for k โ‰ฅ 2) can be partitioned around a single interior pivot element into:

  1. A left sub-interval of length Fkโˆ’2 โˆ’ 1 elements,
  2. The pivot element itself (1 element), and
  3. 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:

  1. 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.
  2. 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.
  3. 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 AlgorithmSplit Ratio (Left : Right)Index Arithmetic RequiredWorst-Case ComparisonsAverage Comparisons (Uniform)Unimodal Function Adaptation
Binary Search1 : 1 (0.500 : 0.500)Addition + division by 2 (or right shift)โŒŠlog2 nโŒ‹ + 1โ‰ˆ log2 n โˆ’ 1Requires 2 probes per step (dichotomous)
Fibonacci Search1/ฯ†2 : 1/ฯ† (0.382 : 0.618)Addition and subtraction onlyโ‰ˆ logฯ†(โˆš5 ยท n) โ‰ˆ 1.44 log2 nโ‰ˆ 1.055 log2 nMinimax optimal (1 new probe per step)
Golden-Section Search1/ฯ†2 : 1/ฯ† (continuous)Floating-point multiplication by ฯ† โˆ’ 1Continuous convergence (0.618k)1.44 log2(1 / ฮต)Standard continuous unimodal search
Exponential SearchDoubling + 1 : 1 binaryBit shift + addition2โŒŠlog2 iโŒ‹ + 2O(log i)Bounded by target rank i
Jump SearchFixed block m = โˆšnAddition of constant m2โˆšn โˆ’ 1โˆšn โˆ’ 0.5Sequential 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:

Fk = (ฯ†k โˆ’ ฯˆk) / โˆš5 โ‰ˆ ฯ†k / โˆš5

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:

k โ‰ˆ logฯ†(โˆš5 ยท n) = (log2 n) / (log2 ฯ†) + logฯ† โˆš5 โ‰ˆ 1.44042 ยท log2 n + 1.672

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:

Cavg(n) = ((โˆš5 / 5) logฯ† n) + O(1) โ‰ˆ 1.0423 ยท log2 n

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

  1. 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
  2. Ferguson, D. E. (1960). "Fibonaccian searching." Communications of the ACM, 3(12), 648. https://doi.org/10.1145/367487.367496
  3. Overholt, K. J. (1973). "Efficiency of the Fibonacci search method." BIT Numerical Mathematics, 13(1), 92โ€“96. https://doi.org/10.1007/BF01933527
  4. 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/
๐Ÿงฌ Support Open Science
Explore interactive science games on LowKey Games or browse scientific apparel & accessories in the CRV Science Shop.
๐Ÿ’ก Spot an inaccuracy or have primary literature to expand this article?
Submit a citation or revision note using your shared CRV Science / LowKey Games profile ID.
Suggest Revision