Quote from Introduction to Algorithms.
In an amortised analysis, we average the time required to perform a sequence of data-structure operations over all the operations performed.
The potential method of amortised analysis represents the prepaid work as “potential energy”, or just “potential”, which can be released to pay for future operations. We associate the potential with the data structure as a whole rather than with specific objects within the data structure.
The potential method works as follows. We will perform operations, starting with an initial data structure
. For each i=1,2,…,n, we let
be the actual cost of the
th operation and
be the data structure that results after applying the
th operations to the data structure
. A potential function
maps each data structure
to a real number
, which is the potential associated with data structure
. The amortized cost
of the
th operation with respect to potential function
is defined by
(1)
The amortised cost of each operation is therefore its actual cost plus the change in potential due to the operation. By equation (1), the total amortised cost of the operation is
Consider an extensible array that can store an arbitrary number of integers. Each add operation inserts a new element after all the elements previously inserted. If there are no empty cells left, a new array of double the size is allocated, and all the data from the old array is copied to the corresponding entries in the new array. For instance, consider the following sequence of insertions, starting with an array of length 1: 
The table is doubled in the second, third, and fifth steps. As each insertion takes O(n) time in the worst case, a simple analysis would yield a bound of time for n insertions. But it is not this bad. Let’s analyze a sequence of n operations using the potential method.
Suppose we can define a potential function on states of a data structure with the following properties:
, where
is the initial state of the data structure.
for all states
of the data structure occurring during the course of the computation.
Intuitively, the potential function will keep track of the precharged time at any point in the computation. It measures how much saved-up time is available to pay for expensive operations. It is analogous to the bank balance in the banker’s method. But interestingly, it depends only on the current state of the data structure, irrespective of the history of the computation that got it into that state.
We then define the amortised time of the operation as
,
where is the actual cost of the operation and
and
are the states of the data structure before and after the operation, respectively. Thus the amortised time is the actual time plus the change in potential. Ideally,
should be defined so that the amortised time of each operation is small. Thus the change in potential should be positive for low-cost operations and negative for high-cost operations.
Now consider a sequence of operations taking actual times
and producing data structures
starting from
. The total amortised time is the sum of the individual amortised times:
.
Therefore the amortised time for a sequence of operations overestimates of the actual time by , which by assumption is always positive. Thus the total amortised time is always an upper bound on the actual time.
For dynamically resizable arrays with resizing by doubling, we can use the potential function
,
where is the current number of elements and
is the current length of the array. If we start with an array of length 0 and allocate an array of length 1 when the first element is added, and thereafter double the array size whenever we need more space, we have
and
for all
. The latter inequality holds because the number of elements is always at least half the size of the array.
Now we would like to show that adding an element takes amortised constant time. There are two cases.
- If
, then the actual cost is 1,
increased by 1, and
does not change. Then the potential increase by 2, so the amortised time is 1+2 = 3.
- If
, then the array is doubled, so the actual time is
. But the potential drops from
to 2, so amortised time is
.
In both cases, the amortised time is O(1).