TExcelTAD
Home › Online Algorithms & Competitive Analysis › The Harmonic Lower Bound for Randomized Paging

The Harmonic Lower Bound for Randomized Paging

The marking algorithm is 2Hk2H_k-competitive against an oblivious adversary. Can randomization do even better, perhaps a constant? No: Fiat, Karp, Luby, McGeoch, Sleator and Young (1991) proved that every randomized paging algorithm has competitive ratio at least HkH_k against an oblivious adversary, so MARK is optimal up to a factor 2, and the optimal ratio is Θ(log⁡k)\Theta(\log k). This lesson proves the bound with Yao's principle and a coupon-collector computation, verifies each step numerically, and surveys the algorithms that reach HkH_k exactly.

The theorem

Theorem (Fiat et al., 1991). Let the universe have at least k+1k + 1 pages. For every randomized online paging algorithm RR with cache size kk, and every constants c<Hkc < H_k and α\alpha, there is a request sequence σ\sigma with E[R(σ)]>c⋅OPT(σ)+α\mathbb{E}[R(\sigma)] > c \cdot \mathrm{OPT}(\sigma) + \alpha. That is, RR is not better than HkH_k-competitive against an oblivious adversary, even in the non-strict sense.

By Yao's principle it suffices to exhibit input distributions Dn\mathcal{D}_n on which every deterministic algorithm AA satisfies E[A]≥(Hk−o(1)) E[OPT]\mathbb{E}[A] \ge (H_k - o(1))\,\mathbb{E}[\mathrm{OPT}], with E[OPT]→∞\mathbb{E}[\mathrm{OPT}] \to \infty. The distribution: nn requests, each independent and uniform over pages 1,…,k+11, \ldots, k + 1.

Step 1: every deterministic algorithm pays n/(k+1)n/(k+1)

Assume the caches start full (the start-up adds at most kk to every cost, which disappears in the limit). Whatever AA holds in its kk slots at time tt, exactly one of the k+1k + 1 pages is missing, and σt\sigma_t is independent of everything before it, so AA misses at time tt with probability exactly 1k+1\frac{1}{k+1}. By linearity, E[A]=nk+1\mathbb{E}[A] = \frac{n}{k+1} for every deterministic AA. The algorithm's cleverness is irrelevant: on this distribution all online algorithms, deterministic or randomized, are equally good.

python · try it yourself
import random

def lru(reqs, k):
    cache, m = list(range(k)), 0
    for p in reqs:
        if p in cache:
            cache.remove(p)
        else:
            m += 1
            cache.pop(0)
        cache.append(p)
    return m

def lfu(reqs, k):                                  # evict the least frequently requested page
    cache, freq, m = set(range(k)), {}, 0
    for p in reqs:
        freq[p] = freq.get(p, 0) + 1
        if p not in cache:
            m += 1
            cache.remove(min(cache, key=lambda q: (freq.get(q, 0), q)))
            cache.add(p)
    return m

def mark(reqs, k, rng):
    cache, marked, m = set(range(k)), set(), 0
    for p in reqs:
        if p not in cache:
            m += 1
            if marked >= cache:
                marked = set()
            cache.remove(rng.choice(sorted(cache - marked)))
            cache.add(p)
        marked.add(p)
    return m

rng = random.Random(21)
k, n = 5, 30000
reqs = [rng.randrange(k + 1) for _ in range(n)]
print(f"k = {k}, uniform over {k + 1} pages, 1/(k+1) = {1 / (k + 1):.4f}")
for name, misses in [("LRU", lru(reqs, k)), ("LFU", lfu(reqs, k)), ("MARK", mark(reqs, k, rng))]:
    print(f"{name:5} miss rate {misses / n:.4f}")
k = 5, uniform over 6 pages, 1/(k+1) = 0.1667
LRU   miss rate 0.1645
LFU   miss rate 0.1663
MARK  miss rate 0.1691

Step 2: OPT misses once per coupon-collector round

Look at Belady's rule on the random sequence. Suppose OPT misses at time tt. Before the miss its cache holds all pages except σt\sigma_t; it evicts the cached page qq whose next request is furthest away. After the eviction it holds every page except qq, so its next miss is the next request to qq, and qq is, by the choice of the rule, the last of the kk pages other than σt\sigma_t to be requested again. So the gap between two consecutive misses of OPT is the time until all kk pages other than σt\sigma_t have appeared after tt.

With requests uniform over k+1k + 1 pages, collecting kk specific pages is a coupon-collector problem: when ii of them are still missing, each request hits one of them with probability ik+1\frac{i}{k+1}, so the expected wait for the next one is k+1i\frac{k+1}{i}, and

E[gap]=∑i=1kk+1i=(k+1) Hk.\mathbb{E}[\text{gap}] = \sum_{i=1}^{k} \frac{k + 1}{i} = (k + 1)\,H_k .

The gaps are independent and identically distributed (each depends only on the requests after the previous miss), so OPT's misses form a renewal process, and the elementary renewal theorem gives E[OPT]/n→1(k+1)Hk\mathbb{E}[\mathrm{OPT}] / n \to \frac{1}{(k+1)H_k}.

python · try it yourself
import random

def opt_miss_times(reqs, k):
    n = len(reqs)
    nxt, seen = [0] * n, {}
    for t in range(n - 1, -1, -1):
        nxt[t] = seen.get(reqs[t], n + reqs[t])
        seen[reqs[t]] = t
    first = {}
    for t, p in enumerate(reqs):
        first.setdefault(p, t)
    cache = {p: first.get(p, n + p) for p in range(k)}      # start full with pages 0..k-1
    times = []
    for t, p in enumerate(reqs):
        if p not in cache:
            times.append(t)
            del cache[max(cache, key=cache.get)]
        cache[p] = nxt[t]
    return times

rng = random.Random(22)
n = 60000
print(" k   mean gap   (k+1) H_k   (n/(k+1)) / OPT   H_k")
for k in [2, 3, 5, 8, 12]:
    reqs = [rng.randrange(k + 1) for _ in range(n)]
    times = opt_miss_times(reqs, k)
    gaps = [b - a for a, b in zip(times, times[1:])]
    H = sum(1 / i for i in range(1, k + 1))
    ratio = (n / (k + 1)) / len(times)
    print(f"{k:2}   {sum(gaps) / len(gaps):8.2f}   {(k + 1) * H:9.2f}   {ratio:15.3f}   {H:.3f}")
 k   mean gap   (k+1) H_k   (n/(k+1)) / OPT   H_k
 2       4.51        4.50             1.502   1.500
 3       7.30        7.33             1.825   1.833
 5      13.58       13.70             2.263   2.283
 8      24.52       24.46             2.724   2.718
12      39.87       40.34             3.067   3.103

Step 3: conclude with Yao's principle

Every deterministic algorithm has E[A]=nk+1\mathbb{E}[A] = \frac{n}{k+1} (plus a start-up term at most kk), and E[OPT]=n(k+1)Hk(1+o(1))\mathbb{E}[\mathrm{OPT}] = \frac{n}{(k+1)H_k}(1 + o(1)), which tends to infinity. Hence

E[A]E[OPT]→Hk\frac{\mathbb{E}[A]}{\mathbb{E}[\mathrm{OPT}]} \to H_k

for every deterministic AA, and by Yao's principle (online form, non-strict version) no randomized algorithm is better than HkH_k-competitive against an oblivious adversary. ■\blacksquare

Two features make this proof work, and both recur in other randomized lower bounds:

  • The input distribution makes all deterministic algorithms equally bad, so there is no algorithm to analyse.
  • OPT is computed by an explicit offline rule (here Belady's) whose behaviour on random inputs reduces to a classical probability problem.

Algorithms that reach HkH_k

The gap between HkH_k and MARK's 2Hk−12H_k - 1 was closed in two steps.

Algorithm Ratio (oblivious adversary) Notes
MARK (Fiat et al., 1991) 2Hk−12H_k - 1 (exact, Achlioptas, Chrobak and Noga, 2000) simple, O(1)O(1) per request
PARTITION (McGeoch and Sleator, 1991) HkH_k optimal; its state can grow with the length of the sequence
EQUITABLE (Achlioptas, Chrobak and Noga, 2000) HkH_k optimal; works with a bounded description of the offline configurations

Both optimal algorithms track the set of cache configurations that the offline optimum could be in after the requests so far (the "work function" view of the work-function lesson) and maintain a probability distribution over the online configurations that matches it as closely as possible. MARK can be seen as a cruder version that only distinguishes marked from unmarked pages.

The lower bound is also robust in other directions. Against a cache of h<kh < k for OPT, the randomized lower bound becomes about ln⁡kk−h\ln\frac{k}{k-h} (Young, 1991; see Resource Augmentation), and against adaptive adversaries the bound jumps back to kk (Oblivious and Adaptive Adversaries).

Test yourself

On uniformly random requests over k+1k + 1 pages, why do all deterministic algorithms have the same expected cost?

  1. Because they all evict the same page
  2. Because exactly one page is missing from any full cache, and the next request is that page with probability 1/(k+1)1/(k+1), independently of the past
  3. Because OPT is random
  4. Because the cache is empty

What is the expected gap between consecutive misses of OPT on this distribution?

  1. k+1k + 1
  2. (k+1)Hk(k + 1)H_k
  3. kHkkH_k
  4. HkH_k

Which statement about randomized paging against an oblivious adversary is correct?

  1. The optimal ratio is 2Hk2H_k
  2. The optimal ratio is exactly HkH_k, and MARK achieves 2Hk−12H_k - 1
  3. The optimal ratio is kk
  4. Randomization cannot help

Why is this a lower bound on the non-strict ratio, not only the strict one?

  1. Because E[OPT]\mathbb{E}[\mathrm{OPT}] grows linearly with nn
  2. Because the sequences are short
  3. Because MARK is optimal
  4. Because the adversary is adaptive