\documentclass[11pt]{article}
  \usepackage{times}
  \advance\textwidth by0.8in\advance\oddsidemargin by-0.4in
  \advance\textheight by0.8in
  \headheight 0pt\topskip 0pt
\begin{document}
\begin{center}
  \Large
  CS 561 (591): Data Structures and Algorithms\\
  \Large\bf
  Analysis of the Move-to-Front Heuristic
\end{center}

\bigskip
Although this analysis is done in amortized terms, it is not typical
of the amortized analysis used for most algorithms, in that it obtains
a relative, not an absolute result: the analysis show that the 
move-to-front (MTF) heuristic never does worse than twice the cost
of the (unknown) optimal, but it does not tell us what either cost is.
It is pretty easy to see, however, that the worst-case cost, even
over long sequences, is linear time per operation.  Suppose we start
with a list of the first $n$ integers in the natural order $(1,2,\ldots,n)$
and handle the list of requests $(n,n-1,n-2,\ldots,3,2,1,n,n-1,n-2,\ldots)$:
then the MTF algorithm simply rotates the list by one position after
each search---and every search takes linear time.
The relative statement ``no worse than twice the optimal'' is typical
of a style of analysis known as \emph{competitive} analysis, in which
the algorithm at hand is compared with the (usually unknown) optimal.
Competitive analysis invariably uses amortization.

So how do we carry out the competitive analysis of MTF?\ \
We start by comparing it with the optimal \emph{static} list---the
best possible fixed ordering of the list of items given the sequence
of searches that will have to be carried out.  Assume that,
at some step in the handling of these searches, we have to search for
item $x$; further assume that $x$ occurs in the $i$th position in the
MTF list and in the $j$th position in the optimal static list.  Then
the actual cost of a search with the MTF algorithm for item $x$ at
this step is $i$---the number of nodes in the list that have to be traversed
in order to find $x$; similarly the cost in the optimal list is $j$.
We now define a potential for this problem; because our analysis is
a comparison of two strategies, the potential is an assessment of the
differences between the two structures.  For each item $x$ in the lists,
we count the number of items that precede $x$ in the MTF list, but
follow it in the optimal static list.  If we write $\Phi$ for the
overall potential, it is made of a sum of individual potentials
$\Phi = \sum_x \phi_x$, where $\phi_x$ is the potential contribution
of item $x$.

Searching the optimal static list does not alter the potential---only
a change in the position of items can do that.  Searching in the MTF
list does alter the potential, in two ways: first, it brings $x$ to
the front, reducing its contribution to the potential down to zero;
and secondly, it moves an extra item in front of the items that
used to be in the first through $(i-1)$st positions in the list
(and are now in the second through $i$th positions), possibly
increasing their contribution to the potential.
The first contributes a change of $-\phi_x$.  To see how much the
second contributes, note that some item $y$ that sits in front
of $x$ in the original MTF list will see its contribution $\phi_y$
increase after $x$ is moved to the front only if $x$ occurs after
$y$ in the optimal list---that is, only if $y$ occurs in front of
$x$ in the optimal list as well as in the original MTF list.
But we know that we have exactly $i-1-\phi_x$ such items $y$, because
everyone of the $i-1$ items in front of $x$ in the original MTF list
must occur either after $x$ in the optimal list (and we have stated
that there are $\phi_x$ such items) or before it.
Thus the change in potential caused by moving $x$ to the front of the 
MTF list is a decrease of $\phi_x$ (the potential contribution of $x$
drops to zero) and an increase of $1$ for each of the $i-1-\phi_x$
items in front of $x$ in both the original MTF list and the optimal list,
for a total of $\Delta\Phi = -\phi_x + 1\cdot(i-1-\phi_x) = i-1 -2\phi_x$.
The sum of the real cost of searching for $x$ in the MTF list plus the
change in potential is thus
  $$i+\Delta\Phi = i + (i-1 -2\phi_x) = 2(i-\phi_x) -1$$

What can we say about $j$, the cost of the search for $x$ in the optimal
list?\ \ Well, we have just stated that there are $i-1-\phi_x$ items
in front of $x$ in both the original MTF and the optimal lists;
it follows that $j$ is larger than $i-1-\phi_x$---thus we write
$j > (i-\phi_x) -1$ or $j\geq i-\phi_x$.  Multiply each side of this
last inequality by two to get
  $$2j \geq 2(i-\phi_x)$$
and now connect this with our equation for the sum of the real cost
plus the change in potential:
  $$i+\Delta\Phi = 2(i-\phi_x) -1 \leq 2(i-\phi_x) \leq 2j$$
which is the result we needed: the amortized cost of an operation on the
MTF list (real cost plus change in potential) is bounded above by twice
the real cost on an operation on the optimal list.

To get the cost of a sequence of operations, we would simply
sum a collection of such inequalities and obtain
  $$\sum_{ops} MTF(op) \leq \sum_{ops} OPT(op) + (\Phi_{init}-\Phi_{final})$$
Observe that $\Phi$ cannot be negative and that its maximum value
is $n(n+1)/2$; thus any sequence of operations of length $\Omega(n^2)$
sees only a negligible contribution from the potential difference
between the initial and the final states.

Now, if we want to consider that the optimal solution is also allowed
to modify its list, note that the only change that comes up in one
in potential: the MTF cost and potential changes are unaffected, as
is the real cost of searching the optimal list.  Any move of $x$
towards the front of the list can only tend to increase $\Phi$
(because more items can now occur after $x$ in the optimal list
that were in front of $x$ in the original MTF list), which decreases
$\Delta\Phi$ and thus preserves the inequality.  Moving $x$ towards
the back of the list can increase $\Delta\Phi$ by at most the number
of positions by which $x$ is moved; but doing so is not free, because
it forces the search algorithm to move beyond index $j$ in the optimal
list by that same number of positions---so that the same quantity
is added to the two sides of the inequality, which is thus preserved.
Hence we conclude that MTF is never worse than any algorithm that
is restricted to moving just the retrieved item.
\end{document}
