CSC 378: Data Structures and Algorithm Analysis

Move-to-Front Lists

Move-to-Front Lists

Idea: Use a linked list to store elements but, every time an element is sought, move it to the front of the list.

Intuition: Frequently-sought, or high-probability, elements will tend to stay near the front of the list.

For example:

Searching in a Move-to-Front (MTF) list costs only a few pointer assignments more than searching in a normal list. It's also very easy to implement.

But is the move-to-front heuristic really useful? We must somehow measure the quality of this heuristic. To do so, we'll compare the expected search time in a MTF list with that in an optimal list of the same elements.

Note that we can almost never construct the optimal list, since the probability distribution of queries is almost always unknown. So we're hoping that the MTF heuristic gives an expected search time close to that of the optimal list.

MTF Theorem

Given index1.gif elements, name them by their position in the optimal list:

index2.gif .

Then (from the optimal list theorem) index3.gif .

Let index4.gif be the expected search time in the optimal list of these elements.

Let index5.gif be the expected search time in the MTF list of the same elements.

Clearly, index6.gif since the optimal list has minimum expected search time, of all possible lists.

Theorem

index7.gif

Discussion

The theorem says that the expected search time of the MTF list is at most twice optimal. This is a surprising result, since we don't even know the probability distribution!

Consider, for example, these elements and their associated probabilities:

x A B C D
P( x ) 0.1 0.1 0.8 0.0

index8.gif .

The theorem states that index9.gif .

Since we don't know index10.gif , we might have built an arbitrary, static list, like

index11.gif

Had we done so, we would have been stuck forever with an expected search time of index12.gif . Clearly, the MTF list is better, even though it's not optimal. When we don't know the probability distribution, it's best to use an MTF list rather than risk choosing a bad ordering in a static list.

Proof of Theorem

index13.gif

In the MTF list of these elements, let's perform enough searches so that the ordering of the MTF list is unaffected by its initial ordering. Each element will have been sought at least once.

We'll take a ``snapshot'' of the list at this point and will analyse the expected search time.

Let index14.gif be the position of index15.gif in this snapshot. The expected value of index16.gif is (from our definition of expectation)

index17.gif

For example, suppose we have

index18.gif percentage of time
1 50 %
2 10 %
3 20 %
4 20 %

Then

index19.gif

and index20.gif is, on average, in position 2.1.

If we knew index21.gif , we would know index22.gif , since index23.gif .

So what is index24.gif ?

index25.gif

In the summation above, if index26.gif precedes index27.gif , it adds one to the number of preceding elements.

So what is index28.gif ?

For example, suppose index29.gif and index30.gif .

  • In 30% of the searches, index31.gif moves to the front.
  • In 10%, index32.gif moves to the front.
  • In 60%, something else moves to the front. This 60% has no effect on the relative ordering of index33.gif and index34.gif .

Of the 40% of the time that either index35.gif or index36.gif is sought:

  • For index37.gif of that 40%, index38.gif goes to the front.
  • For index39.gif of that 40%, index40.gif goes to the front.

Therefore, in any snapshot of the list, index41.gif .

Generalising from this example, index42.gif .

In the example above, index43.gif .

Thus

index44.gif

Note the symmetry in i and j !

Therefore index45.gif .

Note that index46.gif .

Using this fact:

index47.gif .

That's it! We've proven that index48.gif .

Note that we had to get the index49.gif in order to exploit the symmetry.

The key was to produce the index50.gif term.

It's great that we can prove the the MTF heuristic is actually useful.




Back to the lecture index

Copyright 1998 James Stewart