Algorithms · Visualized

Fibonacci Search

Searching Algorithms

Six search strategies on a sorted array — from the obvious linear scan to log-time binary search and beyond.

Fibonacci search locates a target in a sorted array using Fibonacci numbers to choose probe points instead of a midpoint, narrowing the range with additions and subtractions only — no division at all. Time: O(log n) average, O(log n) worst; space: O(1).

Big-O: Binary O(log n), Linear O(n), Jump O(√n), Interpolation O(log log n) avg, Exponential O(log n).

Fibonacci Search

Searching

Fibonacci search locates a target in a sorted array using Fibonacci numbers to choose probe points instead of a midpoint, narrowing the range with additions and subtractions only — no division at all. This made it attractive on hardware where division was expensive, and it remains a neat example of probe-based search.

How Fibonacci Search Works

  1. Find the smallest Fibonacci number F(k) greater than or equal to the array length n.
  2. Probe the index offset + F(k−2), where offset tracks the excluded left prefix.
  3. Compare the target to the value at the probe.
  4. If it's smaller, discard the portion after the probe and shift down to the F(k−2) sub-range.
  5. If it's larger, move the offset past the probe and reduce the Fibonacci window by two steps.
  6. Repeat until the window collapses; check the remaining last element explicitly.

Fibonacci Search Worked Example

Input: {array: [10, 22, 35, 40, 45, 50, 80, 82, 85, 90, 100], target: 85}

Smallest Fibonacci ≥ 11 is 13, so F=13, F(k−2)=5. Probe at index 4 (value 45); 85 > 45 → shift the offset right and shrink the window. Next probe lands near index 7 (82); 85 > 82 → shift again. Next probe at index 8 (85) → match. Found 85 at index 8.

Fibonacci SearchO(log n)
Probe the range using Fibonacci numbers instead of midpoints — addition and subtraction only.
10
0
22
1
35
2
40
3
45
4
50
5
80
6
82
7
85
8
90
9
100
10
Step 1 / 9
Default Current / Compare Swap / Write Settled Active / Path Pivot / Reject Locked (hollow) Target
Fibonacci Search for 85: smallest Fibonacci ≥ n = 11 is F = 13; offset F(k−2) = 5.
Python · Searching Algorithms in Code
def fibonacci_search(a, target):
    n = len(a)
    fm2, fm1, fm = 0, 1, 1
    while fm < n:
        fm2, fm1, fm = fm1, fm, fm1 + fm
    offset = -1
    while fm > 1:
        i = min(offset + fm2, n - 1)
        if a[i] < target:
            fm, fm1, fm2 = fm1, fm2, fm1 - fm2
            offset = i
        elif a[i] > target:
            fm, fm1, fm2 = fm2, fm1 - fm2, fm - fm2
        else:
            return i
    if fm1 and offset + 1 < n and a[offset + 1] == target:
        return offset + 1
    return -1

Behind the Scenes Execution

Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.

Fibonacci Search Time & Space Complexity

BestO(1) — first probe hits
AverageO(log n)
WorstO(log n)
SpaceO(1)

When to Use Fibonacci Search

  • Searching where division is expensive relative to addition/subtraction.
  • Searching data on slow random-access media (historically magnetic tape).
  • Teaching probe-based search strategies beyond simple bisection.

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits

Keep the momentum going

Step through a related structure, pattern or course — the ideas reinforce each other and stick faster.