TExcelTAD
Home › Online Algorithms & Competitive Analysis › Yao's Principle for Online Lower Bounds

Yao's Principle for Online Lower Bounds

Upper bounds for randomized algorithms are proved by analysing one algorithm. Lower bounds are harder: they must hold for every randomized algorithm, that is, for every probability distribution over deterministic algorithms, an infinite family with no structure to grab. Yao's principle (Yao, 1977) turns the problem around. Instead of fighting every randomized algorithm, pick one probability distribution over inputs and show that every deterministic algorithm does badly on average. Deterministic algorithms against a fixed input distribution are much easier to analyse, and the principle says the result transfers.

The game behind it

Take a finite online problem: finitely many deterministic algorithms A1,…,AmA_1, \ldots, A_m (for example, all strategies on sequences of a fixed length) and finitely many request sequences σ1,…,σn\sigma_1, \ldots, \sigma_n. Define the payoff matrix

Mij=Ai(σj)OPT(σj).M_{ij} = \frac{A_i(\sigma_j)}{\mathrm{OPT}(\sigma_j)} .

A randomized algorithm is a probability vector pp over the rows; an oblivious adversary choosing a sequence at random is a probability vector qq over the columns. Von Neumann's minimax theorem for finite zero-sum games says

min⁡pmax⁡j∑ipiMij=max⁡qmin⁡i∑jqjMij.\min_{p} \max_{j} \sum_i p_i M_{ij} = \max_{q} \min_{i} \sum_j q_j M_{ij} .

The left side is the best expected ratio a randomized algorithm can guarantee against an oblivious adversary. The right side is the best an input distribution can force on deterministic algorithms. So any distribution qq gives a lower bound, min⁡i∑jqjMij\min_i \sum_j q_j M_{ij}, on the randomized ratio, and the best distribution gives exactly the right value.

Yao's principle (online form). Let D\mathcal{D} be a probability distribution over request sequences such that for every deterministic online algorithm AA

Eσ∼D[A(σ)]≥c⋅Eσ∼D[OPT(σ)].\mathbb{E}_{\sigma \sim \mathcal{D}}\bigl[A(\sigma)\bigr] \ge c \cdot \mathbb{E}_{\sigma \sim \mathcal{D}}\bigl[\mathrm{OPT}(\sigma)\bigr] .

Then no randomized online algorithm is better than cc-competitive in the strict sense against an oblivious adversary. If there are such distributions with ED[OPT]\mathbb{E}_{\mathcal{D}}[\mathrm{OPT}] arbitrarily large, the same holds for the non-strict ratio.

Proof

A randomized algorithm RR is a distribution over deterministic algorithms AA. Average the hypothesis over A∼RA \sim R and swap the two expectations (both are over independent choices):

Eσ∼D[EA∼R[A(σ)]]=EA∼R[Eσ∼D[A(σ)]]≥c⋅Eσ∼D[OPT(σ)].\mathbb{E}_{\sigma \sim \mathcal{D}}\Bigl[\mathbb{E}_{A \sim R}[A(\sigma)]\Bigr] = \mathbb{E}_{A \sim R}\Bigl[\mathbb{E}_{\sigma \sim \mathcal{D}}[A(\sigma)]\Bigr] \ge c \cdot \mathbb{E}_{\sigma \sim \mathcal{D}}[\mathrm{OPT}(\sigma)] .

If RR were c′c'-competitive, EA[A(σ)]≤c′OPT(σ)+α\mathbb{E}_{A}[A(\sigma)] \le c' \mathrm{OPT}(\sigma) + \alpha for every σ\sigma; averaging over σ∼D\sigma \sim \mathcal{D} gives c⋅E[OPT]≤c′⋅E[OPT]+αc \cdot \mathbb{E}[\mathrm{OPT}] \le c' \cdot \mathbb{E}[\mathrm{OPT}] + \alpha. With α=0\alpha = 0 this forces c′≥cc' \ge c. If E[OPT]\mathbb{E}[\mathrm{OPT}] can be made arbitrarily large, dividing by it shows c′≥c−α/E[OPT]→cc' \ge c - \alpha / \mathbb{E}[\mathrm{OPT}] \to c, so c′≥cc' \ge c for every fixed α\alpha.

Note the form: the hypothesis compares ratios of expectations, E[A]/E[OPT]\mathbb{E}[A]/\mathbb{E}[\mathrm{OPT}], not expectations of ratios. Both forms are valid lower-bound tools (the matrix form above uses expected ratios), but they must not be mixed: showing E[A/OPT]≥c\mathbb{E}[A/\mathrm{OPT}] \ge c for a distribution where OPT\mathrm{OPT} varies does not prove the online form's hypothesis.

The minimax theorem at work: ski rental with B=4B = 4

Ski rental with buying price B=4B = 4 is a finite game if seasons are cut at D≤12D \le 12 days. Rows are the buying days j=1,…,13j = 1, \ldots, 13 (day 13 means "never within the horizon"), columns the season lengths. The program solves both sides of the minimax equation as linear programs: the algorithm's side (choose pp to minimize the worst column) and the adversary's side (choose qq to maximize the best row). They agree, and the value equals the formula 1/(1−(1−1/B)B)1/(1 - (1 - 1/B)^B) from Randomized Ski Rental.

python · try it yourself
import numpy as np
from scipy.optimize import linprog

B, horizon = 4, 12
days = range(1, horizon + 1)
def cost(j, D):                      # buy on the morning of day j if the season is still on
    return D if D < j else (j - 1) + B
M = np.array([[cost(j, D) / min(D, B) for D in days] for j in range(1, horizon + 2)])
m, n = M.shape

# algorithm: minimize v subject to sum_i p_i M[i, j] <= v for every column j
res_p = linprog(np.r_[np.zeros(m), 1], A_ub=np.c_[M.T, -np.ones(n)], b_ub=np.zeros(n),
                A_eq=[np.r_[np.ones(m), 0]], b_eq=[1], bounds=[(0, None)] * m + [(None, None)],
                method="highs")
# adversary: maximize w subject to sum_j q_j M[i, j] >= w for every row i
res_q = linprog(np.r_[np.zeros(n), -1], A_ub=np.c_[-M, np.ones(m)], b_ub=np.zeros(m),
                A_eq=[np.r_[np.ones(n), 0]], b_eq=[1], bounds=[(0, None)] * n + [(None, None)],
                method="highs")
p = res_p.x[:m]
print(f"algorithm's guarantee min_p max_D = {res_p.x[-1]:.4f}")
print(f"adversary's bound     max_q min_j = {res_q.x[-1]:.4f}")
print(f"formula 1/(1 - (1 - 1/B)^B)       = {1 / (1 - (1 - 1 / B) ** B):.4f}")
print("optimal Pr[buy on day j], j = 1..4:", " ".join(f"{x:.4f}" for x in p[:4]))
algorithm's guarantee min_p max_D = 1.4629
adversary's bound     max_q min_j = 1.4629
formula 1/(1 - (1 - 1/B)^B)       = 1.4629
optimal Pr[buy on day j], j = 1..4: 0.1543 0.2057 0.2743 0.3657

The algorithm's optimal distribution puts all its weight on days 1 to 4, each day BB−1=43\frac{B}{B-1} = \frac{4}{3} times as likely as the one before. An optimal adversary mixes short seasons (D<BD < B) with long ones (D≥BD \ge B; all long seasons look the same to strategies that buy by day BB, so the solver may pick any of them).

A first lower bound: paging with k+1k + 1 pages

Here is the distribution behind the HkH_k lower bound of The Harmonic Lower Bound for Randomized Paging: requests uniformly at random from k+1k + 1 pages. Whatever a deterministic algorithm keeps in its kk slots, the next page is the missing one with probability 1k+1\frac{1}{k+1}, so every deterministic algorithm has the same expected cost, about n/(k+1)n/(k+1) over nn requests. OPT misses much less often: after a miss it evicts the page requested furthest in the future, and the next miss comes only after all kk other pages have been requested again, a coupon-collector wait of about (k+1)Hk(k+1)H_k requests.

python · try it yourself
import random

def opt_misses(reqs, k):
    """Belady with precomputed next-use times (linear time after the first pass)."""
    nxt, last = [0] * len(reqs), {}
    for t in range(len(reqs) - 1, -1, -1):
        nxt[t] = last.get(reqs[t], len(reqs))
        last[reqs[t]] = t
    cache, misses = {}, 0                       # page -> time of its next request
    for t, p in enumerate(reqs):
        if p not in cache:
            misses += 1
            if len(cache) == k:
                del cache[max(cache, key=cache.get)]
        cache[p] = nxt[t]
    return misses

def fifo_misses(reqs, k):
    cache, misses = [], 0
    for p in reqs:
        if p not in cache:
            misses += 1
            if len(cache) == k:
                cache.pop(0)
            cache.append(p)
    return misses

rng = random.Random(5)
n = 60000
print(" k   E[ALG]/n   1/(k+1)   E[OPT]/n   ratio   H_k")
for k in [2, 4, 8]:
    reqs = [rng.randrange(k + 1) for _ in range(n)]
    alg, opt = fifo_misses(reqs, k), opt_misses(reqs, k)
    H = sum(1 / i for i in range(1, k + 1))
    print(f"{k:2}   {alg / n:8.4f}   {1 / (k + 1):7.4f}   {opt / n:8.4f}   {alg / opt:5.3f}   {H:.3f}")
 k   E[ALG]/n   1/(k+1)   E[OPT]/n   ratio   H_k
 2     0.3366    0.3333     0.2241   1.502   1.500
 4     0.2006    0.2000     0.0966   2.077   2.083
 8     0.1100    0.1111     0.0407   2.702   2.718

FIFO stands in for every deterministic algorithm; any other would show the same miss rate up to noise. The measured ratio matches HkH_k, so by Yao's principle no randomized paging algorithm beats HkH_k against an oblivious adversary. The careful version of this argument, with the renewal process behind OPT's misses, is in the lesson on the randomized lower bound.

How to use the principle

  1. Choose the distribution to make every deterministic algorithm equal. If all deterministic algorithms have the same expected cost, there is nothing left to analyse (paging above). In general, equalizing the best responses is exactly what the optimal qq in the minimax theorem does.
  2. Compute or bound E[OPT]\mathbb{E}[\mathrm{OPT}] separately. OPT sees the sampled sequence, so this is an offline question.
  3. Make the expected optimum grow if you want a non-strict bound: use longer and longer sequences.

Yao's principle gives lower bounds only against oblivious adversaries, which is the right target: against adaptive adversaries, randomized lower bounds follow from deterministic ones (Oblivious and Adaptive Adversaries).

Test yourself

Yao's principle reduces a lower bound for randomized online algorithms to what?

  1. An upper bound for one deterministic algorithm
  2. A lower bound on the expected cost of every deterministic algorithm on one input distribution
  3. A bound on the running time
  4. An adaptive adversary argument

Every deterministic algorithm has E[A]≥2 E[OPT]\mathbb{E}[A] \ge 2\,\mathbb{E}[\mathrm{OPT}] on a distribution with E[OPT]=5\mathbb{E}[\mathrm{OPT}] = 5. What does Yao's principle give?

  1. No randomized algorithm is better than 2-competitive in the strict sense
  2. No randomized algorithm is better than 2-competitive in the non-strict sense
  3. Every randomized algorithm is 2-competitive
  4. Nothing, the expected optimum is too small

Why is the uniform distribution over k+1k + 1 pages convenient for a paging lower bound?

  1. OPT has no misses on it
  2. Every deterministic algorithm misses with probability exactly 1/(k+1)1/(k+1) per request once its cache is full
  3. LRU becomes optimal
  4. It forces the adversary to be adaptive