Recall the optimal list :Move-to-Front Heuristic![]()
where
![]()
![]()
(
is the probability that the next search is for
)
We don't know the probabilities. The structure is a dynamic linked list; upon search for an item, that item is moved to the front of the list. In this way, frequently-sought items will tend to stay near the front.What is
as compared to
?
Probabilistic analysis shows that -
- but says nothing about the worst case.
We will show that -
This is a much stronger statement!
Probabilistic analysis tells us what happens on average, not what happens in the worst case. Amortized analysis gives us the worst-case analysis for a sequence of operations.Potential Method
Letbe the optimal static list.
Let
( L ) be the number of pairs of elements of L which are in a different order in
( called 'inversions' ).
What is the minimum
e.g. = a b c d
L = a c d b
( L ) = 2
( L ) ?
0 when L =What is the maximum( L )?
When L = reverse(), every pair is inversed,
there are
Letbe L after the
search.
Letbe the
find operation on
.
( Letbe
in an optimal list )
Fromto
,
changes order with each element in A.
's order remains the same for the elements in B.
precedes
in
.
Suppose
:
![]()
- the new inversion increases
by 1.
SupposeBack to index:
- the inversion disappears, sodecreases by 1.
Let a be the number of elements
such that j < k.
ais the number of inversions created. |A| - ais the number of inversions removed. ![]()
Then -We want to compare![]()
![]()
![]()
![]()
![]()
![]()
we are paying 2 for each inversion created.
and
, the time to find
in
.
But 'a' is the number of elements![]()
![]()
(
k is in the
position )
such that j < k,
which is
the number of elements
such that j < k,
which is
k - 1.
So
But the list has some elements in it before the first 'find'. For the whole sequence :![]()
![]()
,
Sowhere
![]()
![]()
![]()
![]()
![]()
![]()
![]()
where
doesn't change as M increases.
![]()
and
as
.
This is better than the probabilistic analysis, since it applies to all sequences of finds, not just the average case.