next up previous
Next: Up: Previous:

Aggregate Method

Let n = number of items in table.

The worst-case running time of this algorithm is O(n).

For n calls the worst-case running time is O(n2).

Double the table size when full. This expansion is performed once every power of 2 steps in 1...n.

Assuming \(c_i \;=\; \left\{ \begin{array}{ll}
i & {\rm if} \; i-1 \; {\rm is} \; {\rm power} \; {\rm of} \; 2 \\
1 & {\rm otherwise} \end{array} \right.\),

\(\sum_{i=1}^{n} c_i \;\leq n \;+\;
\sum_{j=0}^{\lfloor lgn \rfloor} 2^j\)
This is a geometric series \(\sum_{k=0}^n x^k \;=\;
\frac{x^{n+1} - 1}{x-1}\)
\(<\; n \;+\; 2n\)
\(=\; 3n\)

The total amortized cost of a single call to TableInsert is 3.


next up previous
Next: Up: Previous: