|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
| • |
Charge
7 credits for each
|
|
|
|
operation
|
|
|
|
– |
Amortized
time per
|
|
|
|
operation
is O(1)
|
|
|
| • |
addElement()
(when no
|
|
|
|
doubling
occurs) uses one
|
|
|
credit
to pay for itself and
|
|
|
|
stores
6 credits with the item
|
|
| • |
The
other operations use
|
|
|
|
their
7 credits to pay for
|
|
|
themselves
with the extra 6
|
|
|
|
credits
thrown away
|
|
|
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
| • |
When
a table doubling
|
|
|
|
occurs
(say at size 2i)
|
|
|
|
– |
It takes 3*2i credits to pay
|
|
|
|
|
for
creating the new array
|
|
|
|
and
copying all the data
|
|
|
|
– |
We use
the credits stored at
|
|
|
positions
2i-1 to 2i
|
|
|
| • |
Note
that the previous
|
|
|
|
doubling
occurred when the
|
|
|
size
was 2i-1
|
|
|
|
– |
Thus
the credits stored at
|
|
|
|
2i-1
to 2i are unspent
|
|
|
|