Algorithm Search⌘K

Proofs: Fibonacci search

These are the human proofs of Fibonacci search, at full length.

Fibonacci search finds the mode of a strictly unimodal sequence with the optimal number of evaluations full

This proof shows: correctness.

We use the pseudocode of the page and the Fibonacci numbers F0=0F_0 = 0, F1=1F_1 = 1, Fk+2=Fk+1+FkF_{k+2} = F_{k+1} + F_k. Let ff be strictly unimodal for a maximum on {1,…,n}\{1, \ldots, n\} with mode mm, and let N≥1N \ge 1 be the smallest number with FN+2≥n+1F_{N+2} \ge n + 1.

Padding. Extend ff to gg on {1,…,FN+2−1}\{1, \ldots, F_{N+2} - 1\} by g(i)=f(i)g(i) = f(i) for i≤ni \le n and g(i)=−M−ig(i) = -M - i for i>ni > n, where MM is larger than −min⁡f-\min f. Then gg is strictly unimodal with the same mode mm: it increases up to mm, decreases from mm to nn, and keeps decreasing after nn with values below all values of ff. Line L7 does not evaluate g(q)g(q) for q>nq > n; it treats qq as worse than pp, which is what gg answers as long as p≤np \le n. The invariant below shows p≤np \le n, so the run is exactly the run on gg.

Comparison lemma. For x1<x2x_1 < x_2: g(x1)<g(x2)g(x_1) < g(x_2) implies m>x1m > x_1; g(x1)>g(x2)g(x_1) > g(x_2) implies m<x2m < x_2; g(x1)=g(x2)g(x_1) = g(x_2) implies x1<m<x2x_1 < m < x_2. This is the lemma on the page unimodal function.

Invariant. Before each test of line L5, with kk the value of the counter:

  1. lo<p<hilo < p < hi, and the two parts p−lop - lo and hi−phi - p are Fk+1F_{k+1} and Fk+2F_{k+2} in some order;
  2. lo<m<hilo < m < hi;
  3. 1≤p≤n1 \le p \le n and fp=f(p)fp = f(p);
  4. the number of evaluations made so far is at most N−kN - k.

Initialization. Lines L2 to L4 set lo=0lo = 0, hi=FN+2hi = F_{N+2}, p=FNp = F_N and k=N−1k = N - 1. The parts are FN=Fk+1F_N = F_{k+1} and FN+2−FN=FN+1=Fk+2F_{N+2} - F_N = F_{N+1} = F_{k+2}. Since 1≤m≤n<FN+21 \le m \le n < F_{N+2}, item 2 holds. If N=1N = 1, then p=F1=1≤np = F_1 = 1 \le n. If N≥2N \ge 2, minimality of NN gives FN+1≤nF_{N+1} \le n, so p=FN≤FN+1≤np = F_N \le F_{N+1} \le n. One evaluation has been made, and N−k=1N - k = 1.

Maintenance. Let k≥1k \ge 1. Then Fk+2=Fk+1+Fk>Fk+1F_{k+2} = F_{k+1} + F_k > F_{k+1}, so the larger part is the one of length Fk+2F_{k+2}, and line L6 picks it. Suppose it is the right part, hi−p=Fk+2hi - p = F_{k+2}, so q=p+Fkq = p + F_k with p<q<hip < q < hi because 1≤Fk<Fk+21 \le F_k < F_{k+2}. (The left case is the mirror image.)

  • If q≤nq \le n and f(q)>f(p)f(q) > f(p) (line L8), the lemma gives m>pm > p, so p<m<hip < m < hi. The new state is lo′=plo' = p, p′=qp' = q, hi′=hihi' = hi, with parts FkF_k and Fk+2−Fk=Fk+1F_{k+2} - F_k = F_{k+1}. Also p′=q≤np' = q \le n and fp=f(q)fp = f(q).
  • Otherwise (line L9) g(q)≤g(p)g(q) \le g(p): either q>nq > n, and then g(q)<g(p)g(q) < g(p) by the padding, or f(q)≤f(p)f(q) \le f(p). If g(q)<g(p)g(q) < g(p) the lemma gives m<qm < q; if g(q)=g(p)g(q) = g(p) it gives p<m<qp < m < q. In both cases lo<m<qlo < m < q. The new state is hi′=qhi' = q with parts Fk+1F_{k+1} and FkF_k, and pp is unchanged.

In both cases, with k′=k−1k' = k - 1, the parts are Fk′+1F_{k'+1} and Fk′+2F_{k'+2}, and at most one evaluation was made, so item 4 holds.

Termination and result. Each iteration decreases kk by 1, so the loop stops with k=0k = 0. Then the parts are F1=F2=1F_1 = F_2 = 1, so lo=p−1lo = p - 1 and hi=p+1hi = p + 1. By item 2 the only integer strictly between them, pp, is mm. Line L11 returns mm after at most NN evaluations, by item 4. □\square

Optimality. By the discrete theorem on the page unimodal optimization, no method can guarantee to find the mode of every strictly unimodal function on nn points with fewer than NN evaluations, where NN is the smallest number with n≤FN+2−1n \le F_{N+2} - 1. This is the NN of the algorithm, so Fibonacci search is optimal in the worst case.

Back to Fibonacci search