## Lecture 26: Online Algorithms

Aram asked how the random algorithm does for paging: at each time just pick a random page to evict from the cache. Jason sent in an example where the optimum is 1, but the expected cost for RANDOM is k. The sequence is:

$\displaystyle 1,2,\ldots, k, (0, 1, 2, \ldots, k-1)^*$

The optimal action is to evict ${k}$ when you see the first ${0}$, with an optimal cost of 1. But the random algorithm, on each cache miss, will pick a random page to evict, until it finally hits on ${k}$. Each time it has a 1-in-k chance of success, which leads to an expected cost of ${k}$.

In fact, Raghavan and Snir show that any memoryless randomized algorithm for paging cannot have competitive ratio less than ${k}$. They have a similar construction, and give sequences where the ratio remains ${k}$ even when the optimal costs go to infinity. (Else we could give a weak-competitiveness bound with an additive factor of ${k}$.)