Purpose: Andrew Yao’s 1980 theorem giving the precise conditions under which the optimal split point of an interval DP is monotone — the theoretical foundation that licenses Knuth optimization.

The Theorem

Consider

Yao’s conditions. If the weight function satisfies

  1. Quadrangle inequality (QI):
  2. Monotonicity on intervals:

then itself satisfies the quadrangle inequality, and the argmin is monotone:

That monotonicity is precisely what reduces the DP to .

Why this matters

It converts “I noticed the optimum seems monotone” into a checkable criterion. If you can verify QI and interval monotonicity for your cost function, the speedup is guaranteed correct. If you cannot, the speedup may silently produce wrong answers on some inputs — which is far worse than being slow.

Verifying QI in practice

Write a brute-force checker before trusting the optimization:

bool checkQI(int n, function<long long(int,int)> w) {
    for (int a = 0; a < n; a++)
      for (int b = a; b < n; b++)
        for (int c = b; c < n; c++)
          for (int d = c; d < n; d++)
            if (w(a,c) + w(b,d) > w(a,d) + w(b,c)) return false;
    return true;
}

Run it on with random weights. Thirty seconds of checking saves an hour of debugging a wrong-answer verdict.

Cost functions that satisfy QI

QI?
with (range sum)yes
yes
yes
number of distinct values in yes
yes (concave of a Monge function)
(matrix chain)no — stays

Concave vs convex

Two dual forms appear in the literature:

  • Concave QI () — used above, gives monotone argmin for minimisation;
  • Convex QI (inequality reversed) — gives monotone argmin for maximisation, and drives the convex form of CHT and the SMAWK variants.

Getting the direction wrong is the second most common source of bugs here, after failing to check the condition at all.

Yao also proved Yao’s minimax principle: the expected cost of the best randomized algorithm on the worst input equals the cost of the best deterministic algorithm on the worst input distribution. It is the standard tool for proving randomized lower bounds — e.g. that any randomized comparison sort needs expected comparisons.

Variants / Use Cases