next up previous
Next: Up: Previous:

Analysis

From this result we can analyze the run time of BuildHeap.


\begin{displaymath}\sum_{h=0}^{\lfloor lg n \rfloor} \lceil \frac{n}{2^{h+1}} \r...
... O(n*1/2 \; \sum_{h=0}^{\lfloor lg n \rfloor} \; \frac{h}{2^h})\end{displaymath}

Note that \(\sum_{k=0}^{\infty} x^k \;=\; \frac{1}{1 - x}\), for \(\mid x \mid \;<\; 1\). The derivative of both sides,
\(\frac{d}{dx}(\sum_{k=0}^{\infty} x^k) \;=\;
\frac{d}{dx}(\frac{1}{1 - x})\), is equal to \(\sum_{k=0}^{\infty} k x^{k-1} \;=\; \frac{1}{(1 - x)^2}\).



Multiplying both sides of the equivalence by x we get
\(\sum_{k=0}^{\infty} k x^k \;=\; \frac{x}{(1 - x)^2}\).
In our case k = h and x = 1/2.
Thus
\(\sum_{h=0}^{\infty} \frac{h}{2^h} \;=\; \frac{1/2}{(1 - 1/2)^2}\) = 2, x = 1/2.

Thus the run time is O(n * 1/2 * 2) = O(n).


next up previous
Next: Up: Previous: