Skip to content
StackDecode
SearchingAnimated

Fibonacci Search

Binary-search variant that splits by Fibonacci numbers using only + and −.

Time

O(log n)

Extra space

O(1)

Use it for

Sorted data where division is costly.

How it works

  1. Like binary search but splits the list using Fibonacci numbers instead of halving, so it only uses addition and subtraction.
  2. Find the smallest Fibonacci number F(k) ≥ n.
  3. Probe index offset + F(k−2). If the value is too small, move the offset there and step down one Fibonacci number; if too big, step down two.
  4. Stop when the Fibonacci number reaches 1; check the last candidate.
  5. O(log n) time.

Watch it run

Loading animation…