%
% This is the LaTeX template file for lecture notes for CS294-1,
% On-line Computation \& Network Algorithms.  When preparing 
% LaTeX notes for this class you must use this template.
%
% To familiarize yourself with this template, the body contains
% some examples of its use.  Look them over.  Then you can
% run LaTeX on this file.  After you have LaTeXed this file then
% you can look over the result either by printing it out with
% dvips or using xdvi.
%

\documentstyle[psfig,twoside,11pt]{article}
\setlength{\oddsidemargin}{0.25 in}
\setlength{\evensidemargin}{-0.25 in}
\setlength{\topmargin}{-0.6 in}
\setlength{\textwidth}{6.5 in}
\setlength{\textheight}{8.5 in}
\setlength{\headsep}{0.75 in}
\setlength{\parindent}{0 in}
\setlength{\parskip}{0.1 in}

%
% The following commands set up the lecnum (lecture number)
% counter and make various numbering schemes work relative
% to the lecture number.
%
\newcounter{lecnum}
\renewcommand{\thepage}{\thelecnum-\arabic{page}}
\renewcommand{\thesection}{\thelecnum.\arabic{section}}
\renewcommand{\theequation}{\thelecnum.\arabic{equation}}
\renewcommand{\thefigure}{\thelecnum.\arabic{figure}}
\renewcommand{\thetable}{\thelecnum.\arabic{table}}

%
% The following macro is used to generate the header.
%
\newcommand{\lecture}[4]{
   \pagestyle{myheadings}
   \thispagestyle{plain}
   \newpage
   \setcounter{lecnum}{#1}
   \setcounter{page}{1}
   \noindent
   \begin{center}
   \framebox{
      \vbox{\vspace{2mm}
    \hbox to 6.28in { {\bf CS294-1~ On-line Computation \& Network Algorithms
                        \hfill Spring 1997} }
       \vspace{4mm}
       \hbox to 6.28in { {\Large \hfill Lecture #1: #2  \hfill} }
       \vspace{2mm}
       \hbox to 6.28in { {\it Lecturer: #3 \hfill Scribe: #4} }
      \vspace{2mm}}
   }
   \end{center}
   \markboth{Lecture #1: #2}{Lecture #1: #2}
   \vspace*{4mm}
}

%
% Convention for citations is authors' initials followed by the year.
% For example, to cite a paper by Leighton and Maggs you would type
% \cite{LM89}, and to cite a paper by Strassen you would type \cite{S69}.
% (To avoid bibliography problems, for now we redefine the \cite command.)
% Also commands that create a suitable format for the reference list.
%\renewcommand{\cite}[1]{[#1]}
%\def\beginrefs{\begin{list}%
        %{[\arabic{equation}]}{\usecounter{equation}
         %\setlength{\leftmargin}{2.0truecm}\setlength{\labelsep}{0.4truecm}%
         %\setlength{\labelwidth}{1.6truecm}}}
%\def\endrefs{\end{list}}
%\def\bibentry#1{\item[\hbox{[#1]}]}

%Use this command for a figure; it puts a figure in wherever you want it.
%usage: \fig{NUMBER}{SPACE-IN-INCHES}{CAPTION}
\newcommand{\fig}[3]{
			\vspace{#2}
			\begin{center}
			Figure \thelecnum.#1:~#3
			\end{center}
	}
% Use these for theorems, lemmas, proofs, etc.
\newtheorem{theorem}{Theorem}[lecnum]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}
\newenvironment{proof}{{\bf Proof:}}{\hfill\rule{2mm}{2mm}}

% **** IF YOU WANT TO DEFINE ADDITIONAL MACROS FOR YOURSELF, PUT THEM HERE:
\newcommand{\Cost}{{\rm Cost}}
\newcommand{\Opt}{{\rm OPT}}
\newcommand{\Adv}{{\rm ADV}}
\newcommand{\On}{{\rm ON}}
\newtheorem{principle}[theorem]{Principle}
\begin{document}
%FILL IN THE RIGHT INFO.
\lecture{4}{January 30}{Yair Bartal}{Tzu-Yi Chen}
%\footnotetext{These notes are partially based on those of Nigel Mansell.}

% **** YOUR NOTES GO HERE:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

In this lecture we begin by reviewing some basic definitions and then
go on to examine the random-marking algorithm for the paging problem
in more detail, often generalizing to draw conclusions regarding
randomized algorithms in general.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Review} 

\subsection{Definition of Competitiveness}
We first repeat the definition for deterministic algorithms and then
define it for randomized algorithms.

\begin{definition}[$c$-competitiveness]
For deterministic algorithms, an algorithm $A$ is $c$-competitive iff
\begin{eqnarray*} 
\exists a \geq 0 \;\mbox{s.t.}\; \forall \sigma,\;\;
A(\sigma) \leq c \cdot \;\mbox{\Opt} (\sigma) + a
\end{eqnarray*}
This is equivalent to saying
\begin{eqnarray*}
\exists a \geq 0 \;\mbox{s.t.}\; \forall \sigma \forall \mbox{\Adv},\;\; A(\sigma) \; \leq c \cdot \mbox{\Adv} (\sigma) + a
\end{eqnarray*}
The intuition is that the adversary \Adv plays against $A$ and tries to
maximize $c$.
\end{definition}

The definition can be extended to randomized algorithms by adding expectations
as follows.  A randomized algorithm $A$ is $c$-competitive iff
\begin{eqnarray*} 
\exists a \geq 0 \;\mbox{s.t.}\; \forall \sigma,\;\;
E(A(\sigma)) \leq c \cdot \mbox{\Opt}(\sigma) + a
\end{eqnarray*}
This is equivalent to saying
\begin{eqnarray*}
\exists a \geq 0 \;\mbox{s.t.}\; \forall \sigma \forall \mbox{\Adv},\;\; E(A(\sigma)) \; \leq c \cdot \mbox{\Adv} (\sigma) + a
\end{eqnarray*}

\subsection{Definition of an Adversary}
\Adv\hspace*{1mm} stands for an adversary.  This is an algorithm which tries to
maximize $c$, whereas we (the on-line player)
try to minimize $c$.  The adversary does this
by choosing sequences of inputs.  For example, with the paging problem,
the adversary could consistently choose to request pages not in the cache, 
forcing our algorithm to page fault on every request.

When dicussing randomized algorithms it is important to
define carefully the exact power given to the adversary.
There are several kinds of adversaries (formally defined in \cite{BBKTW}):
\begin{itemize}
\item {\bf oblivious adversary:} This adversary must pick the sequence 
	completely in advance, without knowing anything about the coin
	tosses of the other algorithm.  The definition given above
        applies to this kind of adversary. Randomized algorithms often
        perform especially well against such adversaries.
\item {\bf adaptive adversary:} These are adversaries which can see the
	coin tosses of the other algorithm and adapt to them.  Randomized
	algorithms do not perform as well here.  For adaptive adversaries,
	the definition of competitiveness must be adjusted as follows:
	\begin{itemize}
	\item {\bf on-line:} An on-line adaptive adversary must serve
		the sequence upon generation of requests. \\
\begin{eqnarray}
\label{rand-comp}
E(A(\sigma)) \leq c \cdot E(\mbox{\Adv}(\sigma)) + a.
\end{eqnarray}
	\item {\bf off-line:} An off-line adaptive adversary may serve 
		the sequence optimally at the end. \\
		$$E(A(\sigma)) \leq c \cdot E(\mbox{\Opt}(\sigma)) + a.$$
	\end{itemize}
\end{itemize}

Note that definition \ref{rand-comp} is the most general and 
we may use it in all three cases once defining the set of advesaries considered.

\begin{theorem}
For the paging problem, the competitive ratio of any random on-line 
algorithm against an adaptive on-line algorithm is $\geq k$.
\end{theorem}
This will be proved in the next lecture in the more general context
of the $k$-server problem.

For an algorithm $A$. Let $\rho_{\mbox{\sc obl}}(A),\rho_{\mbox{\sc adol}}(A),
\rho_{\mbox{\sc adoff}}(A)$ be its competitive ratios against 
the three kinds of adversaries
then the following relations hold:

\begin{claim}
$\rho_{\mbox{\sc obl}}(A) \leq \rho_{\mbox{\sc adol}}(A) \leq\rho_{\mbox{\sc adoff}}(A)$
\end{claim}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Random Marking}

In contrast the competitive ratio of randomized algorithms
for the paging problem against an oblivious advesary is $H_k$ defined
below. (Note that $\ln k < H_k < \ln k + 1$.)

\begin{definition}[$H_i$]
$H_i$ is the $i$-th harmonic number, so $H_i = 1 + \frac{1}{2} + \frac{1}{3} + \ldots + \frac{1}{n}$.
\end{definition}

We will prove that the Random Marking algorithm of \cite{FKLMSY} is
$2H_k$-competitive. This analysis has been tightened by 
\cite{ACN} to show the competitive ratio of Random Marking
is actualy $2H_k-1$. Optimal $H_k$-competitive algorithms were first given
by \cite{MS} and then by \cite{ACN}. Both algorithms are
quite complicated and will not be dicussed here.

The Random Marking paging algorithm works in phases as follows:
\begin{itemize}
\item initially (at the beginning of a phase), all the pages in the cache
	are unmarked.
\item upon a request for a page $p$:
	\begin{description}
	\item [case 1] $p$ is in the cache $\rightarrow$ mark $p$.
	\item [case 2] $p$ is not in the cache $\rightarrow$ if all the
		pages in the cache are marked, then unmark all the pages 
		and start a new phase.  Evict a uniformly chosen random
		unmarked page.  Fetch $p$ and mark $p$.
	\end{description}
\end{itemize}

Here is a simple illustration of how the random marking algorithm works
on a cache of size 4.

\vspace*{10mm}

\begin{figure}[ht]
\fbox{
\centerline{\psfig{figure=cache.eps,width=5.0in}}
}
\caption{Example of how random marking works}
\end{figure}

We will show that random marking is $2H_k$ competitive.

Next we define a few new terms by first considering the decomposition into 
phases $P_1, P_2, P_3, \ldots$, where the $i$th phase $P_i$ is defined as
the longest subsequence after $P_{i-1}$ that contains requests for at most
$k$-distinct pages.  

We'll label a page:
\begin{itemize}
\item {\bf {\sc old}} for phase $P_i$ if it was in the cache at the beginning
	of the phase.
\item {\bf {\sc new}} for phase $P_i$ if it was requested during phase $P_i$
	but wasn't {\sc old}.
\end{itemize}

Now let $n_i$ be the number of new pages in $P_i$.

\begin{claim}
$\mbox{\Opt}(\sigma) \geq \frac{1}{2}\sum^m_{i=1}n_i$
\end{claim}

\begin{proof}
Let $q_i$ be the number of page faults to {\Opt} during $P_i$.  Then:
\begin{eqnarray*}
q_{i-1} + q_i & \geq & n_i \\
\sum^m_{i=2}(q_{i-1} + q_i) & \geq & \sum^m_{i=2} n_i \\
2\sum^m_{i=1}q_i - q_1 & \geq & \sum^m_{i=2} n_i \\
2\;\mbox{\Opt}(\sigma) & \geq & q_1 + \sum^m_{i=2}n_i \\
2\;\mbox{\Opt}(\sigma) & \geq & \sum^m_{i=1}n_i
\end{eqnarray*}
\end{proof}

\begin{claim}
$\mbox{\sc RMARK}(\sigma) \leq H_k\sum^m_{i=1}n_i$
\end{claim}

\begin{proof}
There have been $k-n_i$ {\sc old} pages
requested in $P_i$.  Let's label these pages $B_1, B_2, \ldots, B_{k-n_i}$
and consider the requests for them.

In particular, given a request for $B_j$, what is the probability that 
this page is in the cache?  We want to know this because 
\begin{eqnarray*}
E(\mbox{\sc RMARK}(\sigma)) = n_i + \sum^{k-n_i}_{j=1}(\mbox{probability 
that $B_j$ is not in the cache when it is first requested})
\end{eqnarray*}

Let $\tilde{n}_j$ be the number of {\sc new} pages requested prior to 
the first request for $B_j$.  Assume there are $(j-1)$ {\sc old} pages 
already marked.  The number of {\sc old} pages previously evicted and 
not yet requested is equal to $\tilde{n}_j$.  Therefore there are 
$k-\tilde{n}_j-(j-1)$ pages which are {\sc old} and unmarked.

\begin{eqnarray*}
E(\mbox{\sc RMARK}(\sigma)) & = & n_i + \sum_{j=1}^{k-n_i} \frac{\tilde{n}_j}{k-(j-1)} \\
\mbox{since}\;\; {\tilde{n}_j} & \leq & n_i \;\; \mbox{we get} \\
E(\mbox{\sc RMARK}(\sigma)) & = & n_i(1 + \sum_{j=n_i+1}^{k} \frac{1}{j}) \\
			    & = & n_i(1+H_k - H_{n_i}) \\
			    & \leq & H_kn_i
\end{eqnarray*}
\end{proof}

\begin{theorem}
Random Marking is $2H_k$-competitive against an oblivious adversary.  \\
(side note: It can be shown to be $2H_k - 1$ competitive, but we won't 
 do that here.)
\end{theorem}

\begin{proof}
\begin{eqnarray*}
E(\mbox{\sc RMARK}(\sigma)) & \leq & H_k\sum^m_{i=1}n_i \\
\frac{1}{2}\sum^m_{i=1}n_i & \leq & \mbox{\Opt}(\sigma) \\
E(\mbox{\sc RMARK}(\sigma)) & \leq & 2H_k\mbox{\Opt}(\sigma)
\end{eqnarray*}
Therefore {\sc RMARK} is $2H_k$ competitive.
\end{proof}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
\section{Lower Bounds for Randomized Algorithms} 

Because it is easier to bound deterministic algorithms than randomized
algorithms, we begin by stating Yao's principle \cite{Yao}, 
which relates deterministic
and randomized algorithms.  Yao's principle is an application of the 
Von-Neumann---Morgenstein Minimax Theorem from basic game theory.  This
section considers an application of Yao's principle for finding lower
bounds for randomized paging algorithms.

\begin{principle}[Yao's Principle]

If we define the following:

\begin{tabular}{lll}
$\cal R$ & $=$ & set of random algorithms \\
$\cal S$ & $=$ & set of all possible sequences \\ 
$\cal D$ & $=$ & set of deterministic algorithms \\
$\cal P$ & $=$ & set of all probability distributions over sequences 
\end{tabular}

and let $f:{\cal D} \times {\cal S} \rightarrow \Re$.

then:
\begin{eqnarray*}
\inf_{A\in{\cal R}} \; \sup_{\sigma\in{\cal S}} E_A(f(A,\sigma)) = \sup_{d\in{\cal P}} \; \inf_{A\in{\cal D}} E_d(f(A,\sigma_d)) 
\end{eqnarray*}
\end{principle}

\begin{proof}
Let 
\begin{eqnarray*}
\sup_{d\in{\cal P}} \; \inf_{A\in{\cal D}} E_d(f(A,\sigma_d)) = C.
\end{eqnarray*}

We'll show
\begin{eqnarray*}
\inf_{A\in{\cal R}} \; \sup_{\sigma\in{\cal S}} E_A(f(A,\sigma)) \geq C
\end{eqnarray*}
(This is the useful direction.  The other direction can be proven
similarly.)

Assume by contradiction that
\begin{eqnarray*}
\exists A \in {\cal R} & \mbox{s.t.} & \sup_{\sigma\in{\cal S}} E_A(f(A,\sigma)) < C \\
\forall d \in {\cal P} & \mbox{s.t.} & E_d(E_A(f(A,\sigma_d))) < C \\
& & E_A(E_d(f(A,\sigma_d))) < C \\
\Rightarrow \exists A \in {\cal D} & \mbox{s.t.} & E_d(f(A,\sigma_d)) < C
\end{eqnarray*}

That is a contradiction, which concludes the sketch of our proof.
\end{proof}

\subsection{The Paging Problem}

We now turn to proving a lower bound for the random marking paging algorithm.

\begin{theorem}
  The competitive ratio of any randomized algorithm for the paging problem
against an oblivious advsversary is at least $H_k$.
\end{theorem}

The $H_k$ lower bound was orginially proved by \cite{FKLMSY}.
However we will present a somewhat more elegant proof,
similar to the one of \cite{BLS} for uniform Metrical Task Systems,
which is based on Yao's principle.

We let $n = k+1$, and define the probability distribution over the request
sequences as follows: every
request is chosen uniformly among all pages with probability $\frac{1}{k+1}$.

Consider a sequence $\sigma$ of length $l$.  
For any on-line algorithm, $E(A(\sigma)) = \frac{l}{k+1}$.  We now examine
the value of $E(\mbox{\Opt}(\sigma))$.

As before we define a phase to be the longest following subsequence 
such that most $k$ distinct pages are requested.

If $X_1 X_2 X_3 \ldots X_m$ defines the sequence of requests, where
$X_i$ is the subsequence of requests in phase $i$, then we know that 
$\mbox{\sc opt}(\sigma) \leq m$, since it would fault exactly once per
phase.  We now want to find the expected value for $m$.

\begin{claim}
\begin{eqnarray*}
E(|X_i|) & \leq & H_k\cdot (k+1) \\
\Rightarrow E(m) & \leq & \frac{l}{H_k\cdot(k+1)}
\end{eqnarray*}
\end{claim}

\begin{proof}
The first equality
is equivalent to the {\it coupon collector problem}, in which you
have n boxes into which you repeatedly toss balls.  Each ball has an
equal probability for falling into each box.  The question is how many
balls need to be thrown before all the boxes have at least one ball.
The coupon
collector problem is well known and a simple analysis shows that
the number of balls $b$ needed to be thrown until all the boxes are filled is:
\begin{eqnarray*}
b & = & 1 + \frac{1}{(\frac{n-1}{n})} + \frac{1}{(\frac{n-2}{n})} + \ldots + \frac{1}{(\frac{1}{n})} \\
  & = & n[1 + \frac{1}{2} + \frac{1}{3} + \ldots + \frac{1}{n}] \\
  & = & nH_n
\end{eqnarray*}
where $H_n$ is the $n$-th harmonic number.

The analogy to paging is as follows --- each empty box corresponds to
an unmarked page, and each full box corresponds to a marked page.  The
balls correspond to requests for pages.  When all the boxes are full,
all the pages are marked, and a new phase begins.  Since we are interested 
in the expected number of requests before a new phase begins, we get
\begin{eqnarray*}
E(|X_i|) = nH_n - 1 = nH_{n-1} = (k+1)H_k.
\end{eqnarray*}

The second inequality follows from basic Renwal Theory.
\end{proof}


And, finally, a little graph that shows approximately how competitive
all these paging algorithms really are.
This is based on experimental results by Young \cite{Young}.

\vspace*{5mm}

\begin{figure}[ht]
\fbox{
\centerline{\psfig{figure=alg_comp.eps,width=4.0in}}
}
\caption{Competitive ratios of various paging algorithms as a function of
cache size.}
\end{figure}

\begin{thebibliography}{AAA}

\bibitem[ACN96]{ACN}
D.~Achlioptas, M.~Chrobak and J.~Noga.
Competitive Analysis of Randomized Paging Algorithms.
In {\em Proc. 4th European Symposium on Algorithms},
Springer, LNCS 1136, pages 419-430, 1996.

\bibitem[BBKTW90]{BBKTW} S.~Ben-David, A.~Borodin, R.M.~Karp, G.~T\'{a}rdos, and
A.~Wigderson. On the Power of Randomization in On-line Algorithms. In
{\em Proc. of the 22nd Ann. ACM Symp. on Theory of Computing}, pages 379-386,
May 1990.

\bibitem[BLS87]{BLS} A.~Borodin, N.~Linial, and M.~Saks. An Optimal On-Line
Algorithm for Metrical Task Systems. In {\em Proc. of the 19th Ann. ACM Symp
on Theory of Computing}, pages 373-382, May 1987.

\bibitem[FKLMSY91]{FKLMSY} A.~Fiat, R.M.~Karp, M.~Luby, L.A.~McGeoch,
D.D.~Sleator , and N.E.~Young. Competitive Paging Algorithms.
Journal of Algorithms, 12(4), pages 685-699, 1991.

\bibitem[MS91]{MS}
L.A.~McGeoch and D.D.~Sleator.
A Strongly Competitive Randomized Paging Algorithm, 1991.
Submitted to {\em Algorithmica}.

\bibitem[Yao77]{Yao} A.C.~Yao.  Probabilistic Computations:  Towards
a Unified Measure of Complexity.  In {\em Proc. of the 17th Annual
Symposium on Foundations of Computer Science}, pp. 222-227,
1977.

\bibitem[Young94]{Young} N.~Young.
The $k$-Server Dual and Loose Competitiveness for Paging.
In {\em Proc. 2nd Annual ACM-SIAM Symp. on Discrete Algorithms}, 
pages 241-250 (title: ``On-line caching as cache size varies''). 
Also {\em Algorithmica}, 11(6):525-541, 1994. 

\end{thebibliography}

\end{document}



