Oh My Algorithm
Algorithm Guidecomplexity: O(log n)

Fibonacci Search

Partitions the range using Fibonacci numbers. Because it computes indices with only addition and subtraction — no division — it can beat binary search on hardware where division is expensive or where cache-friendly access matters.

01Fibonacci Search

Starting Fibonacci search. It carves the range by Fibonacci numbers, choosing each probe with additions and subtractions only — no division.

The first probe is index 4, holding 45. Compare it with the target 89.

45 is smaller than 89. Keep only the right side and step the Fibonacci numbers down one.

The next probe is index 7, holding 78.

78 also falls short of 89. Move right again and shrink the range further.

This probe lands on 98, at the end of the array.

98 is larger than 89. The target is to the left, so step the Fibonacci numbers down two and cut the range sharply.

The probed slot holds 89 — a match, on the fourth probe.

Search complete · 89 sits at index 8. It replaces binary search where division is expensive, as on embedded hardware.

5
12
23
34
45
56
67
78
89
98
1 / 9

02 Understand It Simply

For Everyone
🔑How It Works

Divides the range at Fibonacci numbers, narrowing it with additions and subtractions only, never a division.

💡In Plain Words

Splits the range with the Fibonacci sequence.

It uses only addition and subtraction (no division), which helps on certain hardware.

📍Where It's Used
  • Environments where division is costly
  • cache-friendly access

03 Python Implementation

A clean, readable reference implementation of the core logic of Fibonacci Search.

core_implementation.py
def fibonacci_search(arr, target):
    n = len(arr)
    fib_m2, fib_m1 = 0, 1
    fib_m = fib_m2 + fib_m1
    while fib_m < n:
        fib_m2, fib_m1 = fib_m1, fib_m
        fib_m = fib_m2 + fib_m1
    offset = -1
    while fib_m > 1:
        i = min(offset + fib_m2, n - 1)
        if arr[i] < target:
            fib_m, fib_m1 = fib_m1, fib_m2
            fib_m2 = fib_m - fib_m1
            offset = i
        elif arr[i] > target:
            fib_m = fib_m2
            fib_m1 -= fib_m2
            fib_m2 = fib_m - fib_m1
        else:
            return i
    return -1

04 Frequently Asked Questions

FAQ
What is Fibonacci Search?+

Partitions the range using Fibonacci numbers. Because it computes indices with only addition and subtraction — no division — it can beat binary search on hardware where division is expensive or where cache-friendly access matters.

What is the time complexity of Fibonacci Search?+

The time complexity of Fibonacci Search is O(log n). Follow the step-by-step visualization to see exactly why.

Where is Fibonacci Search used?+

Environments where division is costly, cache-friendly access.

What's a simple analogy for Fibonacci Search?+

Divides the range at Fibonacci numbers, narrowing it with additions and subtractions only, never a division.