The Harmonic Lower Bound for Randomized Paging
The marking algorithm is -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 against an oblivious adversary, so MARK is optimal up to a factor 2, and the optimal ratio is . This lesson proves the bound with Yao's principle and a coupon-collector computation, verifies each step numerically, and surveys the algorithms that reach exactly.
The theorem
Theorem (Fiat et al., 1991). Let the universe have at least pages. For every randomized online paging algorithm with cache size , and every constants and , there is a request sequence with . That is, is not better than -competitive against an oblivious adversary, even in the non-strict sense.
By Yao's principle it suffices to exhibit input distributions on which every deterministic algorithm satisfies , with . The distribution: requests, each independent and uniform over pages .
Step 1: every deterministic algorithm pays
Assume the caches start full (the start-up adds at most to every cost, which disappears in the limit). Whatever holds in its slots at time , exactly one of the pages is missing, and is independent of everything before it, so misses at time with probability exactly . By linearity, for every deterministic . The algorithm's cleverness is irrelevant: on this distribution all online algorithms, deterministic or randomized, are equally good.
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 . Before the miss its cache holds all pages except ; it evicts the cached page whose next request is furthest away. After the eviction it holds every page except , so its next miss is the next request to , and is, by the choice of the rule, the last of the pages other than to be requested again. So the gap between two consecutive misses of OPT is the time until all pages other than have appeared after .
With requests uniform over pages, collecting specific pages is a coupon-collector problem: when of them are still missing, each request hits one of them with probability , so the expected wait for the next one is , and
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 .
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 (plus a start-up term at most ), and , which tends to infinity. Hence
for every deterministic , and by Yao's principle (online form, non-strict version) no randomized algorithm is better than -competitive against an oblivious adversary.
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
The gap between and MARK's was closed in two steps.
| Algorithm | Ratio (oblivious adversary) | Notes |
|---|---|---|
| MARK (Fiat et al., 1991) | (exact, Achlioptas, Chrobak and Noga, 2000) | simple, per request |
| PARTITION (McGeoch and Sleator, 1991) | optimal; its state can grow with the length of the sequence | |
| EQUITABLE (Achlioptas, Chrobak and Noga, 2000) | 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 for OPT, the randomized lower bound becomes about (Young, 1991; see Resource Augmentation), and against adaptive adversaries the bound jumps back to (Oblivious and Adaptive Adversaries).
Test yourself
On uniformly random requests over pages, why do all deterministic algorithms have the same expected cost?
- Because they all evict the same page
- Because exactly one page is missing from any full cache, and the next request is that page with probability , independently of the past
- Because OPT is random
- Because the cache is empty
What is the expected gap between consecutive misses of OPT on this distribution?
Which statement about randomized paging against an oblivious adversary is correct?
- The optimal ratio is
- The optimal ratio is exactly , and MARK achieves
- The optimal ratio is
- Randomization cannot help
Why is this a lower bound on the non-strict ratio, not only the strict one?
- Because grows linearly with
- Because the sequences are short
- Because MARK is optimal
- Because the adversary is adaptive