No Free Lunch Theorems

What Wolpert and Macready proved about search algorithms averaged over all problems, the sharpened theorem for sets closed under permutation, why such sets are rare, what the theorems do and do not imply for evolutionary algorithms, and why they fail in continuous domains. Proved by a counting argument shown in full on three points, and checked by exhaustive enumeration of all 6,561 functions on a three-bit search space.

Wolpert and Macready (1997) proved that, averaged uniformly over all functions between finite sets, every non-revisiting search algorithm, deterministic or stochastic, has the same distribution of every performance measure. The sharpened theorem (Schumacher, Vose and Whitley, 2001) holds for a set of functions exactly when the set is closed under permutation (c.u.p.). Such sets are rare: on three bits with three values, only $2^{45} - 1$ of the $2^{6561} - 1$ non-empty sets are, about $10^{-1962}$ of them. Over all 6,561 of those functions a fixed order and a hill climber have identical histograms. On the 743 smooth ones, not c.u.p., the hill climber needs a mean of 2.370 evaluations to find a maximum, the fixed order 2.501. In continuous domains the theorems fail (Auger and Teytaud, 2010).

On 50-bit OneMax, the bit-by-bit method of the evolutionary algorithm loop needs exactly 51 evaluations, about an eighth of what the $(1+1)$ EA needs. On the Trap function of fitness landscapes, the same EA never found the optimum in 100,000 evaluations. A method whose first guess is the all-zeros string finds it at once. Each method seems to have problems it suits. Is any search method better than the others in general, over all problems at once?

The No Free Lunch (NFL) theorem for optimization of Wolpert and Macready (1997) answers no, in a precise sense. Averaged over all possible fitness functions on a finite search space, every search algorithm performs exactly as well as every other.

A small case shows how strong that is. Take a search space of eight points, the bitstrings of length three, and suppose each point can score 0, 1, or 2. There are $3^8 = 6{,}561$ possible fitness functions. Now compare two search algorithms:

  • The first evaluates the points in a fixed order, $000, 001, 010, \dots, 111$, whatever it sees.
  • The second is a hill climber. It starts at $111$. At each step it evaluates an unvisited neighbor (one bit flip away) of the best point found so far. If that point has no unvisited neighbor, it takes the first unvisited point in the fixed order.

Run both on all 6,561 functions and record, for each, the best value found after $m$ evaluations. The hill climber uses everything it learns, and the fixed order uses nothing. Yet the two histograms are identical for every $m$, count for count.

The theorem is precise and its proof is short; its interpretation has been argued over ever since. First we set out the abstract model the theorem is about. Then we state the theorem, see why it holds, and prove it by counting on three points. Next comes the sharpened version, which says exactly which sets of problems it applies to. Finally we set out what it implies for evolutionary algorithms, what it does not, and why it fails in continuous domains. The second half uses the vocabulary of fitness landscapes.

The setting

The theorem concerns a deliberately abstract model of black-box optimization:

  • A finite search space $X$ and a finite set of values $Y$, totally ordered. A problem is a function $f : X \to Y$, and $\mathcal{F} = Y^X$ is the set of all such functions. The example has $\lvert X \rvert = 8$, $\lvert Y \rvert = 3$, and $\lvert \mathcal{F} \rvert = 6{,}561$.
  • A search algorithm chooses the next point to evaluate from the history of points evaluated so far and their values. It learns about $f$ only by evaluating it. The algorithm is non-revisiting: it never evaluates the same point twice.
  • After $m$ evaluations the algorithm has produced a sequence of values $d^y_m = \bigl(f(x_1), \dots, f(x_m)\bigr)$. A performance measure is any function of this sequence, such as the best value seen, or the number of evaluations until the best value was first seen.

The restriction to non-revisiting algorithms is less limiting than it looks. A revisit gains no information, so an algorithm that revisits can be compared fairly by counting only its distinct evaluations, which is what Wolpert and Macready do. Real evolutionary algorithms do revisit points, and an evaluation spent on a duplicate is simply wasted.

The theorem

For any two algorithms $a_1$ and $a_2$, any number of evaluations $m$, and any sequence of values $d^y_m$,

$$\sum_{f \in \mathcal{F}} P(d^y_m \mid f, m, a_1) = \sum_{f \in \mathcal{F}} P(d^y_m \mid f, m, a_2).$$

Here $P(d^y_m \mid f, m, a)$ is the probability that algorithm $a$, run for $m$ evaluations on $f$, observes the sequence $d^y_m$. This is Theorem 1 of Wolpert and Macready (1997). They define algorithms as deterministic and show in their Section III-B that the result extends to stochastic ones, by repeating the proof with a probability distribution over the unvisited points in place of a single next point. A shorter route to the extension is this. Fix in advance, independently of $f$, the choice a stochastic algorithm would make after every possible history. Each such fixing is a deterministic non-revisiting algorithm, so a stochastic algorithm is a probability mixture of deterministic ones whose weights do not depend on $f$. The sum over $f$ is the same for every member of the mixture, and therefore for the mixture.

For a deterministic algorithm, $P(d^y_m \mid f, m, a)$ is 1 for the one sequence the algorithm produces on $f$, and 0 otherwise. So the theorem says that the two algorithms produce exactly the same multiset of value sequences across all functions. Since any performance measure is a function of the sequence, every performance measure has the same distribution across all functions, and the same average.

The reason is easiest to see probabilistically. Choosing $f$ uniformly from $\mathcal{F}$ is the same as choosing each value $f(x)$ independently and uniformly from $Y$. Whatever the algorithm has seen so far, the values at the points it has not yet visited are still independent and uniform. So whichever unvisited point it picks next, the value it observes is a fresh uniform draw. Every algorithm, however clever, observes a sequence of independent uniform values. Picking points at random without replacement does exactly as well.

The whole theorem on three points

The smallest interesting case can be written out completely. Let $X = \{p, q, r\}$ and $Y = \{0, 1\}$, so there are $2^3 = 8$ functions. Algorithm F evaluates $p$, $q$, $r$ in that order. Algorithm A is adaptive: it evaluates $q$ first, then $r$ if $f(q) = 1$ and $p$ otherwise, and then the remaining point.

The table lists, for every function, the points each algorithm visits and the sequence of values it observes (script tools/experiments/evolution/nfl_small.py).

$f(p)\,f(q)\,f(r)$ F visits F sees A visits A sees
000 p q r 000 q p r 000
001 p q r 001 q p r 001
010 p q r 010 q r p 100
011 p q r 011 q r p 110
100 p q r 100 q p r 010
101 p q r 101 q p r 011
110 p q r 110 q r p 101
111 p q r 111 q r p 111

On five of the eight functions the two algorithms see different sequences. But each column of observed sequences contains each of the eight possible sequences exactly once. So any performance measure computed from the sequences has the same distribution for both algorithms. For example, the best of the first two values is 1 on 6 of the 8 functions for both, and the best of the first value alone on 4.

The table is an instance of a counting argument that proves the theorem for deterministic algorithms in general. The plan in one sentence: an algorithm's observations determine the function, so it cannot make two functions look alike, and every sequence must turn up exactly once.

  1. Fix a deterministic, non-revisiting algorithm and run it on $f$ until it has evaluated every point. It observes a sequence of $\lvert X \rvert$ values.
  2. The sequence determines $f$. The algorithm's first point is fixed; the first value determines its second point; the first two values determine its third; and so on. Replaying the algorithm against the sequence recovers which point received each value, which is all of $f$.
  3. So different functions give different sequences. There are $\lvert Y \rvert^{\lvert X \rvert}$ functions and $\lvert Y \rvert^{\lvert X \rvert}$ possible sequences. The map from functions to sequences is therefore a bijection: as $f$ runs over all functions, the algorithm sees every sequence exactly once.
  4. A given sequence of $m$ first values can be continued to a full sequence in $\lvert Y \rvert^{\lvert X \rvert - m}$ ways, and by step 3 each full sequence comes from exactly one function. Therefore each possible sequence of $m$ first values occurs for exactly $\lvert Y \rvert^{\lvert X \rvert - m}$ functions, for every algorithm. That count does not depend on the algorithm, which is the theorem for deterministic algorithms.

The algorithm decides only which function produces which sequence, not which sequences occur. Step 3 can be checked on the three-bit example. For the two algorithms of the introduction, and for a hill descender that follows the worst point seen, each of the 6,561 functions gives a distinct sequence.

Step 4 gives the first table below directly. The best of $m$ values is at most $v$ exactly when all $m$ values are at most $v$, which happens for a fraction $\bigl((v+1)/\lvert Y \rvert\bigr)^m$ of the functions.

The enumeration confirms this for the two algorithms of the introduction. The table gives, for each $m$, how many of the 6,561 functions leave each algorithm with best value 0, 1, or 2, and the mean.

$m$ Fixed order: 0 / 1 / 2 Hill climber: 0 / 1 / 2 Mean best
1 2,187 / 2,187 / 2,187 2,187 / 2,187 / 2,187 1.000
2 729 / 2,187 / 3,645 729 / 2,187 / 3,645 1.444
4 81 / 1,215 / 5,265 81 / 1,215 / 5,265 1.790
8 1 / 255 / 6,305 1 / 255 / 6,305 1.961

The counts can be checked by hand. The best of $m$ values is 0 only if all $m$ are 0, which happens for $3^{8-m}$ functions (729 for $m = 2$). It is at most 1 for $2^m \cdot 3^{8-m}$ functions, so it is exactly 1 for $2^m 3^{8-m} - 3^{8-m}$ of them (2,187 for $m = 2$). Both algorithms also need, on average, 2.647 evaluations to first see the function's maximum value, with identical histograms.

So all algorithms tie over all functions. The next section says exactly when the tie survives an average over fewer functions: when the set of functions is closed under permutation, and only then.

Sets closed under permutation

The theorem averages over all functions. A natural question is whether it holds for smaller sets, and Schumacher, Vose, and Whitley (2001) answered it exactly.

A permutation $\sigma$ of $X$ shuffles the points, and $f \circ \sigma$ is the function that takes the same values at the shuffled positions. A set of functions $F$ is closed under permutation (c.u.p.) if $f \circ \sigma$ is in $F$ for every $f \in F$ and every permutation $\sigma$. The sharpened NFL theorem states that all algorithms have the same distribution of every performance measure, averaged uniformly over $F$, if and only if $F$ is closed under permutation.

Closure under permutation has a simple description. Two functions are permutations of each other exactly when they take each value the same number of times, that is, when they have the same histogram of values. In one direction, $f \circ \sigma$ takes each value exactly as often as $f$ does, because $\sigma$ is a bijection. In the other, if $f$ and $g$ take each value equally often, then for each value $y$ the points where $g$ equals $y$ can be matched one to one with the points where $f$ equals $y$. The matchings together form a permutation $\sigma$ with $g = f \circ \sigma$. A set is c.u.p. exactly when it is a union of whole histogram classes (Igel and Toussaint, 2003).

Example (one closed set and one that is not). On the three-bit space, the set of functions that take the value 2 at exactly one point is closed under permutation, and the set of functions whose maximum is at $000$ is not. For the first set, shuffling the points keeps the number of points with value 2, so the shuffled function is still in the set. The second is not: a permutation that moves $000$ elsewhere moves the maximum with it.

For example, the functions on the three-bit space that take the value 2 once, 1 twice, and 0 five times form one class. There are $8!/(1!\, 2!\, 5!) = 168$ of them. On that set, the fixed order and the hill climber again give identical histograms. Both need 4.5 evaluations on average to find the single point with value 2, and the number needed is spread evenly over 1 to 8, 21 functions each.

That average matches a general formula that Igel and Toussaint (2004, Theorem 3) restate from their earlier work. Averaged over all functions with $k$ optimal points out of $\lvert X \rvert$, any non-revisiting algorithm needs $(\lvert X \rvert + 1)/(k + 1)$ evaluations to find one, here $9/2$.

The formula has a short derivation. Write $n = \lvert X \rvert$. Averaged over all placements of the $k$ optimal points, the order in which an algorithm visits points does not matter. Until it finds an optimum it has seen only non-optimal values, and the optima are equally likely to be at any point it has not yet visited. So it may as well use a fixed order, and the $k$ optimal points sit at uniformly random positions in it.

They divide the $n - k$ other points into $k + 1$ gaps: before the first optimum, between consecutive optima, and after the last. The gaps have equal expected size. A placement of the optima is the same thing as a list of $k + 1$ gap sizes that add up to $n - k$, every such list is equally likely, and exchanging two gaps in the list gives another such list. So no gap is larger on average than any other, and each has expected size $(n - k)/(k + 1)$. The algorithm evaluates the whole first gap and then the first optimum, so it needs $(n - k)/(k + 1) + 1 = (n + 1)/(k + 1)$ evaluations on average. Enumerating all placements for $n = 8$ gives exactly $9/2$, $3$ and $9/4$ for $k = 1$, 2 and 3.

Igel and Toussaint (2004, Theorem 6) extended the result to non-uniform distributions over functions. All algorithms perform equally, for every performance measure, if and only if functions with the same histogram are equally likely. The condition is again about symmetry: no arrangement of a given set of values may be favored over another.

What the theorems imply

The theorems rule out a certain kind of claim. A statement such as "algorithm $A$ is better than algorithm $B$ on average over all problems" is false for every pair of algorithms. It is also false over any c.u.p. set with uniform weights. Any gain an algorithm shows on some functions is paid for exactly on the others.

Wolpert and Macready drew the practical conclusion that effective optimization depends on a match between the algorithm and the distribution of problems it is run on. A claim that one algorithm is better than another therefore means something only relative to a class of problems. Evolutionary algorithms are not exempt. Averaged over all functions on a finite space, a genetic algorithm does no better than random search without replacement, and no worse.

Example (OneMax is one function). This does not mean that an evolutionary algorithm is no better than random search on OneMax. OneMax is one function, not an average over all of them. On 50-bit OneMax the $(1+1)$ EA of the evolutionary algorithm loop reached the optimum in every run, while the best string random search found in 100,000 draws had a median of 40 ones. The theorem says that this advantage is paid for on other functions, such as Trap, not that it does not exist.

Learning from examples has a no-free-lunch theorem of its own, a different result with a similar moral. PAC Learning and Finite Hypothesis Classes proves it (section "Why the class matters: the no-free-lunch theorem"): for every learner there is a distribution on which it fails although another learner succeeds there. That is a worst case for each learner, not an average over problems, and it means a learner must commit to a restricted class of rules before seeing the data. Empirical Risk Minimization shows what happens without one: a rule that memorizes its sample fits it perfectly and predicts no better than a rule that never looked.

What the theorems do not imply

The theorems do not say that all algorithms are equally good on the problems people actually solve. Those problems are not a c.u.p. set chosen uniformly.

C.u.p. sets are rare. A set of functions is c.u.p. only if it is a union of histogram classes. The number of histogram classes is $\binom{\lvert X \rvert + \lvert Y \rvert - 1}{\lvert X \rvert}$, so the number of non-empty c.u.p. sets is $2^{\binom{\lvert X \rvert + \lvert Y \rvert - 1}{\lvert X \rvert}} - 1$, out of $2^{\lvert Y \rvert^{\lvert X \rvert}} - 1$ non-empty sets in all (Igel and Toussaint, 2003, Theorem 2). For the three-bit example there are $\binom{10}{8} = 45$ classes. So $2^{45} - 1 \approx 3.5 \times 10^{13}$ of the $2^{6561} - 1$ sets are c.u.p., a fraction of about $10^{-1962}$. A set of problems chosen without the symmetry in mind will almost never satisfy the theorem's precondition.

Structure breaks the symmetry. The properties that make problems tractable are defined by neighborhoods, and a non-trivial neighborhood relation is not preserved by arbitrary permutations of the points. Igel and Toussaint (2003, Corollaries 1 and 2) proved a result of this kind. Suppose every function in a set is limited to less than the maximum possible steepness between neighbors, or to fewer than the maximum possible number of local minima. Then the set is not c.u.p. A problem class described as "smooth" or "not maximally rugged" therefore lies outside the theorem. In the terms of fitness landscapes, that is most problem classes anyone cares about.

The enumeration shows the effect on a small scale. Restrict the three-bit example to the 743 smooth functions, those in which neighboring points differ in value by at most 1. This set is not c.u.p., and the two algorithms now differ:

$m$ Fixed order: mean best Hill climber: mean best
2 1.280 1.280
3 1.420 1.444
4 1.503 1.542
5 1.561 1.594
8 1.654 1.654
Mean best value found after m evaluations, for the fixed order, the hill climber, and a hill descender that follows the worst point seen. Over all 6,561 functions (left) the three curves lie exactly on top of each other. Notice that over the 743 smooth functions (right) they separate from the third evaluation on: the hill climber is ahead, the descender behind, and all three meet again at m = 8, when every point has been seen.
Mean best value found after m evaluations, for the fixed order, the hill climber, and a hill descender that follows the worst point seen. Over all 6,561 functions (left) the three curves lie exactly on top of each other. Notice that over the 743 smooth functions (right) they separate from the third evaluation on: the hill climber is ahead, the descender behind, and all three meet again at m = 8, when every point has been seen.

The hill climber needs 2.370 evaluations on average to find a maximum, against 2.501 for the fixed order. The advantage is small, as might be expected on eight points. It is also not uniform: after four evaluations the hill climber is stuck at 0 on 17 functions, against 16 for the fixed order. But the equality that held for every $m$ and every count is gone. The hill climber's assumption, that good points have good neighbors, is built into the set of problems. The script is tools/experiments/evolution/nfl_check.py in the site repository.

Structure helps only an algorithm that matches it. Wolpert and Macready (1997) stress the other side of this point. The mere existence of structure in a problem class does not justify choosing a particular algorithm; the structure has to be known and reflected in the algorithm.

Example (structure used in the wrong direction). A hill descender follows the worst point seen instead of the best. On the smooth functions it finds a maximum more slowly than the fixed order, which ignores what it sees. It needs 2.678 evaluations on average, against the fixed order's 2.501, for exactly the reason the hill climber does better: it uses the structure, but in the wrong direction. Over all 6,561 functions it too ties with the other two.

Averages are not guarantees about a particular problem. The theorems concern averages over a set of functions. They say nothing about which algorithm is better on a given function. Nor do they say anything about problems drawn from a distribution concentrated on structured functions, which is the situation the fitness landscape experiments describe.

Continuous domains

The original theorem needs $X$ and $Y$ to be finite, so that a uniform distribution over all functions makes sense. A continuous search space has no uniform distribution over all functions. Examples are the real vectors that evolution strategies and CMA-ES optimize. There the question becomes what a "random fitness function" should mean.

Auger and Teytaud (2010) formalized random fitness functions as random fields. They showed that, in continuous domains, NFL does not hold: free lunches exist, and some algorithms are better than others averaged over such distributions. They also used the same framework to derive optimal optimization algorithms for a given distribution of fitness functions and a given budget of evaluations.

A floating-point search space is finite, so the original theorem does apply to it formally. That does not rescue the strong reading of NFL. The theorem would require averaging uniformly over all functions on the floating-point grid, nearly all of which look like noise at every scale. Continuous optimizers are designed for, and tested on, functions whose values vary smoothly with their arguments.

What we have learned

The No Free Lunch theorems are correct and their conditions are exact. Averaged uniformly over all functions on a finite space, or over any set closed under permutation, every non-revisiting search algorithm performs the same. The counting proof showed why: an algorithm decides only which function produces which sequence of values, never which sequences occur. But c.u.p. sets are vanishingly rare, and any class defined by smoothness or limited ruggedness lies outside them. The theorems are best read as a statement about where an algorithm's power comes from (Eiben and Smith, 2015, ch. 16). No algorithm is good in general. An algorithm is good on a class of problems when its operators and selection exploit structure that the class actually has.

The course now turns to particular algorithms, starting with the simplest one that exploits neighborhood structure. The first article of local search, hill climbing, specifies its four standard forms and sets out the ways it gets stuck.

References

  • Auger, A., and Teytaud, O. (2010). Continuous lunches are free plus the design of optimal optimization algorithms. Algorithmica, 57(1), 121–146. record
  • Eiben, A. E., and Smith, J. E. (2015). Introduction to Evolutionary Computing, 2nd ed., chapter 16. Springer. record · 35 pages
  • Igel, C., and Toussaint, M. (2003). On classes of functions for which No Free Lunch results hold. Information Processing Letters, 86(6), 317–321. record
  • Igel, C., and Toussaint, M. (2004). A No-Free-Lunch theorem for non-uniform distributions of target functions. Journal of Mathematical Modelling and Algorithms, 3(4), 313–322. record
  • Schumacher, C., Vose, M. D., and Whitley, L. D. (2001). The No Free Lunch and problem description length. In Proceedings of the Genetic and Evolutionary Computation Conference (GECCO 2001), 565–570. Morgan Kaufmann. record
  • Wolpert, D. H., and Macready, W. G. (1997). No free lunch theorems for optimization. IEEE Transactions on Evolutionary Computation, 1(1), 67–82. record · 5 pages

Reviewed: verified, 16 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 8 revisions