See Algorithms
SEE ALGORITHMS

Fibonacci Search Visualization

Fibonacci Search is a comparison-based searching algorithm for sorted arrays that narrows the candidate range using Fibonacci numbers. Instead of dividing an interval into equal 50/50 halves like Binary Search, Fibonacci Search splits it asymmetrically in roughly a 38/62 golden-ratio proportion.

Because consecutive Fibonacci numbers satisfy F(m) = F(m − 2) + F(m − 1), every split uses pure addition and subtraction to compute probe indices. It preserves O(log n) time complexity while keeping probe offsets smaller when moving downward.


Pseudocode

a = 0, b = 1, c = 1
while c < n:
    a = b, b = c, c = a + b
offset = -1
while c > 1:
    i = min(offset + a, n - 1)
    if arr[i] < target:
        offset = i
        c = b, b = a, a = c - b
    else if arr[i] > target:
        c = a, b = b - a, a = c - b
    else: return i
if b == 1 and offset + 1 < n:
    if arr[offset + 1] == target:
        return offset + 1
return -1

Visualizer


CheckingEliminatedFound

Control speed:



Time & Space Complexity

Metric / Operation
Complexity
Description
Best CaseO(1)When the very first Fibonacci probe index matches the target.
Average CaseO(log n)Reduces the search interval according to consecutive Fibonacci ratios (~1.618).
Worst CaseO(log n)Requires at most ~1.44 log₂ n comparisons without any division or bit-shift operations.
Space ComplexityO(1)Maintains only scalar variables for Fibonacci numbers (a, b, c) and offset.

Common Interview Questions

How does Fibonacci Search differ from Binary Search in splitting the search range?

Binary Search splits the interval in half using division, whereas Fibonacci Search splits it at Fibonacci offsets using only addition and subtraction, maintaining O(log n) worst-case time.

Why is there a final check on offset + 1 after the Fibonacci Search loop?

When F(m) c shrinks to 1 with b == 1, one untested candidate element may remain at offset + 1, which must be compared directly against the target.


💬  Discussion

to join the discussion


Curious to Learn More?

Hand-picked resources to deepen your understanding


Learn DSA on Udemy
Learn DSA on Udemy
As an Udemy Associate, I earn from qualifying purchases.

© 2025 See Algorithms. Code licensed under MIT, content under CC BY-NC 4.0