next up previous
Next: Up: Previous:

Analysis

To analyze the amortized cost of the ith TableInsert operation, let

$\;\;\;\;\;$numi denote the number of items stored in the table after the ith operation

$\;\;\;\;\;$sizei denote the total size of the table after the ith operation

$\;\;\;\;\;$\(\Phi_i\) denote the potential after the ith operation

Initially, num0 = 0, size0 = 0, and \(\Phi_0\) = 0.



Consider two cases based on whether a table expansion is done.

No expansion:

\(\hat{c_i} \;=\; c_i \;+\; \Phi_i \;-\; \Phi_{i-1}\)
= 1 + (2*numi-sizei) - (2*numi-1 - sizei-1)
= 1 + (2*numi-sizei) - (2*(numi - 1) - sizei)
= 1 - (-2) = 3


next up previous
Next: Up: Previous: