<s>
In	O
computational	O
complexity	O
theory	O
,	O
the	O
potential	B-General_Concept
method	I-General_Concept
is	O
a	O
method	O
used	O
to	O
analyze	O
the	O
amortized	B-General_Concept
time	I-General_Concept
and	I-General_Concept
space	I-General_Concept
complexity	I-General_Concept
of	O
a	O
data	B-General_Concept
structure	I-General_Concept
,	O
a	O
measure	O
of	O
its	O
performance	O
over	O
sequences	O
of	O
operations	O
that	O
smooths	O
out	O
the	O
cost	O
of	O
infrequent	O
but	O
expensive	O
operations	O
.	O
</s>
<s>
In	O
the	O
potential	B-General_Concept
method	I-General_Concept
,	O
a	O
function	O
Φ	O
is	O
chosen	O
that	O
maps	O
states	O
of	O
the	O
data	B-General_Concept
structure	I-General_Concept
to	O
non-negative	O
numbers	O
.	O
</s>
<s>
If	O
S	O
is	O
a	O
state	O
of	O
the	O
data	B-General_Concept
structure	I-General_Concept
,	O
Φ(S )	O
represents	O
work	O
that	O
has	O
been	O
accounted	O
for	O
(	O
"	O
paid	O
for	O
"	O
)	O
in	O
the	O
amortized	B-General_Concept
analysis	I-General_Concept
but	O
not	O
yet	O
performed	O
.	O
</s>
<s>
The	O
potential	O
value	O
prior	O
to	O
the	O
operation	O
of	O
initializing	O
a	O
data	B-General_Concept
structure	I-General_Concept
is	O
defined	O
to	O
be	O
zero	O
.	O
</s>
<s>
Let	O
o	O
be	O
any	O
individual	O
operation	O
within	O
a	O
sequence	O
of	O
operations	O
on	O
some	O
data	B-General_Concept
structure	I-General_Concept
,	O
with	O
Sbefore	O
denoting	O
the	O
state	O
of	O
the	O
data	B-General_Concept
structure	I-General_Concept
prior	O
to	O
operation	O
o	O
and	O
Safter	O
denoting	O
its	O
state	O
after	O
operation	O
o	O
has	O
completed	O
.	O
</s>
<s>
That	O
is	O
,	O
the	O
amortized	B-General_Concept
time	I-General_Concept
is	O
defined	O
to	O
be	O
the	O
actual	O
time	O
taken	O
by	O
the	O
operation	O
plus	O
C	O
times	O
the	O
difference	O
in	O
potential	O
caused	O
by	O
the	O
operation	O
.	O
</s>
<s>
Despite	O
its	O
artificial	O
appearance	O
,	O
the	O
total	O
amortized	B-General_Concept
time	I-General_Concept
of	O
a	O
sequence	O
of	O
operations	O
provides	O
a	O
valid	O
upper	O
bound	O
on	O
the	O
actual	O
time	O
for	O
the	O
same	O
sequence	O
of	O
operations	O
.	O
</s>
<s>
The	O
total	O
amortized	B-General_Concept
time	I-General_Concept
:	O
</s>
<s>
Since	O
and	O
,	O
,	O
so	O
the	O
amortized	B-General_Concept
time	I-General_Concept
can	O
be	O
used	O
to	O
provide	O
an	O
accurate	O
upper	O
bound	O
on	O
the	O
actual	O
time	O
of	O
a	O
sequence	O
of	O
operations	O
,	O
even	O
though	O
the	O
amortized	B-General_Concept
time	I-General_Concept
for	O
an	O
individual	O
operation	O
may	O
vary	O
widely	O
from	O
its	O
actual	O
time	O
.	O
</s>
<s>
Typically	O
,	O
amortized	B-General_Concept
analysis	I-General_Concept
is	O
used	O
in	O
combination	O
with	O
a	O
worst	B-General_Concept
case	I-General_Concept
assumption	O
about	O
the	O
input	O
sequence	O
.	O
</s>
<s>
With	O
this	O
assumption	O
,	O
if	O
X	O
is	O
a	O
type	O
of	O
operation	O
that	O
may	O
be	O
performed	O
by	O
the	O
data	B-General_Concept
structure	I-General_Concept
,	O
and	O
n	O
is	O
an	O
integer	O
defining	O
the	O
size	O
of	O
the	O
given	O
data	B-General_Concept
structure	I-General_Concept
(	O
for	O
instance	O
,	O
the	O
number	O
of	O
items	O
that	O
it	O
contains	O
)	O
,	O
then	O
the	O
amortized	B-General_Concept
time	I-General_Concept
for	O
operations	O
of	O
type	O
X	O
is	O
defined	O
to	O
be	O
the	O
maximum	O
,	O
among	O
all	O
possible	O
sequences	O
of	O
operations	O
on	O
data	B-General_Concept
structures	I-General_Concept
of	O
size	O
n	O
and	O
all	O
operations	O
oi	O
of	O
type	O
X	O
within	O
the	O
sequence	O
,	O
of	O
the	O
amortized	B-General_Concept
time	I-General_Concept
for	O
operation	O
oi	O
.	O
</s>
<s>
With	O
this	O
definition	O
,	O
the	O
time	O
to	O
perform	O
a	O
sequence	O
of	O
operations	O
may	O
be	O
estimated	O
by	O
multiplying	O
the	O
amortized	B-General_Concept
time	I-General_Concept
for	O
each	O
type	O
of	O
operation	O
in	O
the	O
sequence	O
by	O
the	O
number	O
of	O
operations	O
of	O
that	O
type	O
.	O
</s>
<s>
A	O
dynamic	B-Data_Structure
array	I-Data_Structure
is	O
a	O
data	B-General_Concept
structure	I-General_Concept
for	O
maintaining	O
an	O
array	B-Data_Structure
of	O
items	O
,	O
allowing	O
both	O
random	B-General_Concept
access	I-General_Concept
to	O
positions	O
within	O
the	O
array	B-Data_Structure
and	O
the	O
ability	O
to	O
increase	O
the	O
array	B-Data_Structure
size	O
by	O
one	O
.	O
</s>
<s>
It	O
is	O
available	O
in	O
Java	B-Language
as	O
the	O
"	O
ArrayList	B-Data_Structure
"	O
type	O
and	O
in	O
Python	B-Language
as	O
the	O
"	O
list	O
"	O
type	O
.	O
</s>
<s>
A	O
dynamic	B-Data_Structure
array	I-Data_Structure
may	O
be	O
implemented	O
by	O
a	O
data	B-General_Concept
structure	I-General_Concept
consisting	O
of	O
an	O
array	B-Data_Structure
A	O
of	O
items	O
,	O
of	O
some	O
length	O
N	O
,	O
together	O
with	O
a	O
number	O
n≤N	O
representing	O
the	O
positions	O
within	O
the	O
array	B-Data_Structure
that	O
have	O
been	O
used	O
so	O
far	O
.	O
</s>
<s>
With	O
this	O
structure	O
,	O
random	O
accesses	O
to	O
the	O
dynamic	B-Data_Structure
array	I-Data_Structure
may	O
be	O
implemented	O
by	O
accessing	O
the	O
same	O
cell	O
of	O
the	O
internal	O
array	B-Data_Structure
A	O
,	O
and	O
when	O
n	O
<	O
N	O
an	O
operation	O
that	O
increases	O
the	O
dynamic	B-Data_Structure
array	I-Data_Structure
size	O
may	O
be	O
implemented	O
simply	O
by	O
incrementingn	O
.	O
</s>
<s>
However	O
,	O
when	O
n	O
=	O
N	O
,	O
it	O
is	O
necessary	O
to	O
resize	O
A	O
,	O
and	O
a	O
common	O
strategy	O
for	O
doing	O
so	O
is	O
to	O
double	O
its	O
size	O
,	O
replacing	O
A	O
by	O
a	O
new	O
array	B-Data_Structure
of	O
length2n	O
.	O
</s>
<s>
Therefore	O
,	O
the	O
constant	O
actual	O
time	O
of	O
the	O
operation	O
and	O
the	O
constant	O
increase	O
in	O
potential	O
combine	O
to	O
give	O
a	O
constant	O
amortized	B-General_Concept
time	I-General_Concept
for	O
an	O
operation	O
of	O
this	O
type	O
.	O
</s>
<s>
Allocating	O
a	O
new	O
internal	O
array	B-Data_Structure
A	O
and	O
copying	O
all	O
of	O
the	O
values	O
from	O
the	O
old	O
internal	O
array	B-Data_Structure
to	O
the	O
new	O
one	O
takes	O
O(n )	O
actual	O
time	O
,	O
but	O
(	O
with	O
an	O
appropriate	O
choice	O
of	O
the	O
constant	O
of	O
proportionality	O
C	O
)	O
this	O
is	O
entirely	O
cancelled	O
by	O
the	O
decrease	O
in	O
the	O
potential	O
function	O
,	O
leaving	O
again	O
a	O
constant	O
total	O
amortized	B-General_Concept
time	I-General_Concept
for	O
the	O
operation	O
.	O
</s>
<s>
The	O
other	O
operations	O
of	O
the	O
data	B-General_Concept
structure	I-General_Concept
(	O
reading	O
and	O
writing	O
array	B-Data_Structure
cells	O
without	O
changing	O
the	O
array	B-Data_Structure
size	O
)	O
do	O
not	O
cause	O
the	O
potential	O
function	O
to	O
change	O
and	O
have	O
the	O
same	O
constant	O
amortized	B-General_Concept
time	I-General_Concept
as	O
their	O
actual	O
time	O
.	O
</s>
<s>
Therefore	O
,	O
with	O
this	O
choice	O
of	O
resizing	O
strategy	O
and	O
potential	O
function	O
,	O
the	O
potential	B-General_Concept
method	I-General_Concept
shows	O
that	O
all	O
dynamic	B-Data_Structure
array	I-Data_Structure
operations	O
take	O
constant	O
amortized	B-General_Concept
time	I-General_Concept
.	O
</s>
<s>
Combining	O
this	O
with	O
the	O
inequality	O
relating	O
amortized	B-General_Concept
time	I-General_Concept
and	O
actual	O
time	O
over	O
sequences	O
of	O
operations	O
,	O
this	O
shows	O
that	O
any	O
sequence	O
of	O
n	O
dynamic	B-Data_Structure
array	I-Data_Structure
operations	O
takes	O
O(n )	O
actual	O
time	O
in	O
the	O
worst	B-General_Concept
case	I-General_Concept
,	O
despite	O
the	O
fact	O
that	O
some	O
of	O
the	O
individual	O
operations	O
may	O
themselves	O
take	O
a	O
linear	O
amount	O
of	O
time	O
.	O
</s>
<s>
When	O
the	O
dynamic	B-Data_Structure
array	I-Data_Structure
includes	O
operations	O
that	O
decrease	O
the	O
array	B-Data_Structure
size	O
as	O
well	O
as	O
increasing	O
it	O
,	O
the	O
potential	O
function	O
must	O
be	O
modified	O
to	O
prevent	O
it	O
from	O
becoming	O
negative	O
.	O
</s>
<s>
Consider	O
a	O
stack	B-Application
which	O
supports	O
the	O
following	O
operations	O
:	O
</s>
<s>
Initialize	O
-	O
create	O
an	O
empty	O
stack	B-Application
.	O
</s>
<s>
Push	O
-	O
add	O
a	O
single	O
element	O
on	O
top	O
of	O
the	O
stack	B-Application
,	O
enlarging	O
the	O
stack	B-Application
by	O
1	O
.	O
</s>
<s>
Pop(k )	O
requires	O
O(k )	O
time	O
,	O
but	O
we	O
wish	O
to	O
show	O
that	O
all	O
operations	O
take	O
O(1 )	O
amortized	B-General_Concept
time	I-General_Concept
.	O
</s>
<s>
A	O
Push	O
operation	O
takes	O
constant	O
time	O
and	O
increases	O
Φ	O
by	O
1	O
,	O
so	O
its	O
amortized	B-General_Concept
time	I-General_Concept
is	O
constant	O
.	O
</s>
<s>
A	O
Pop	O
operation	O
takes	O
time	O
O(k )	O
but	O
also	O
reduces	O
Φ	O
by	O
k	O
,	O
so	O
its	O
amortized	B-General_Concept
time	I-General_Concept
is	O
also	O
constant	O
.	O
</s>
<s>
This	O
proves	O
that	O
any	O
sequence	O
of	O
m	O
operations	O
takes	O
O(m )	O
actual	O
time	O
in	O
the	O
worst	B-General_Concept
case	I-General_Concept
.	O
</s>
<s>
We	O
wish	O
to	O
show	O
that	O
Inc	O
takes	O
O(1 )	O
amortized	B-General_Concept
time	I-General_Concept
.	O
</s>
<s>
If	O
the	O
counter	O
initially	O
ends	O
in	O
k	O
1	O
bits	O
,	O
we	O
flip	O
a	O
total	O
of	O
k+1	O
bits	O
,	O
taking	O
actual	O
time	O
k+1	O
and	O
reducing	O
the	O
potential	O
by	O
k−1	O
,	O
so	O
the	O
amortized	B-General_Concept
time	I-General_Concept
is	O
2	O
.	O
</s>
<s>
The	O
potential	O
function	O
method	O
is	O
commonly	O
used	O
to	O
analyze	O
Fibonacci	B-Application
heaps	I-Application
,	O
a	O
form	O
of	O
priority	B-Application
queue	I-Application
in	O
which	O
removing	O
an	O
item	O
takes	O
logarithmic	O
amortized	B-General_Concept
time	I-General_Concept
,	O
and	O
all	O
other	O
operations	O
take	O
constant	O
amortized	B-General_Concept
time	I-General_Concept
.	O
</s>
<s>
It	O
may	O
also	O
be	O
used	O
to	O
analyze	O
splay	B-Data_Structure
trees	I-Data_Structure
,	O
a	O
self-adjusting	O
form	O
of	O
binary	B-Language
search	I-Language
tree	I-Language
with	O
logarithmic	O
amortized	B-General_Concept
time	I-General_Concept
per	O
operation	O
.	O
</s>
