Programming
Techniques
G. Manacher, S. Graham
Editors
On Self-Organizing
Sequential Search
Heuristics
Ronald Rivest
Massachusetts Institute of Technology
This paper examines a class of heuristics for main-
taining a sequential list in approximately optimal
order
with
respect to
the average time
required to search for
a specified element, assuming that each element is
searched for with a fixed
probability independent
of
previous searches performed. The "move to
front" and
"transposition"
heuristics are shown to be optimal
to
within a constant factor, and the transposition rule is
shown
to be
the more
efficient of the two. Empirical
evidence suggests
that transposition
is in fact
optimal
for any distribution
of search probabilities.
Key
Words and
Phrases: searching, self-organizing,
list-processing, heuristics
CR Categories: 3.74, 5.25
Heuristics for Maintaining a Sequential List
We consider heuristics for maintaining a sequential
list in approximately optimal order, prove that the
"transposition" heuristic is more efficient than the
"move to front" heuristic analyzed by Knuth in [6, pp.
Copyright (~) 1976, Association for Computing Machinery, Inc.
General permission to republish, but not for profit, all or part
of this material is granted provided that
ACM's
copyright notice
is given and that reference is made to the publication, to its date
of issue, and to the fact that reprinting privileges were granted
by permission of the Association for Computing Machinery.
This work was performed at Institut de Recherche d'Informa-
tique et d'Automatique, 78-Rocquencourt, France, and completed
at MIT under NSF research grant no. GJ-43634X. Author's pres-
ent address: M1T, Project
MAC,
NE43-804, 545 Technology
Square, Cambridge, MA 02139.
63
398-399], and present experimental evidence that the
transposition heuristic is in fact optimal.
Suppose we have a set of n records R1, Rx,.
..,
Rn
which we list in an arbitrary order r, so that Ri is in
position r(i) for l < i < n. At each instant of time we
are presented with a key Ki and asked to retrieve the
associated record Ri. We do so by examining in turn
each position of the list until Ri is found in position 7r(i).
This search costs r(i) units of time to perform.
Let us assume that each key Ki is presented in-
dependently with probability p~. The expected cost
(average search length) for a permutation r is then
cost(r) =
Y~
pit(i).
(1)
l<i<n
We assume without loss of generality throughout that
pl _> p;+l for 1 < i < n. Thus
cost(r)
is minimized when
r is the identity permutation, since the records are then
in order of decreasing probability of being requested.
In practice, the relevant probabilities p~ are seldom
known a priori, so that the optimal ordering can not be
arranged in advance. A random initial arrangement can
be expected to perform ~poorly, so we consider self-
organizing schemes by which the initial ordering is
gradually transformed on the basis of experience into a
hopefully less costly arrangement.
A "counter" scheme immediately spfi:'gs to mind,
whereby we record the frequencyf~ of requests for each