next up previous
Next: Up: Previous:

Exercise 7.1-2

Show that an n-element heap has height $\lfloor$ lg n $\rfloor$



\psfig{figure=figures/f3-2.ps,width=4in,height=2in}




\begin{displaymath}1 \;+\; \sum_{i=0}^{h - 1} 2^i \;\leq\; n \;\leq\; \sum_{i=0}^{h} 2^i
\;<\; \sum_{i=0}^{h} 2^i \;+\; 1\end{displaymath}


\begin{displaymath}1 \;+\; \frac{2^h - 1}{2-1} \;\leq\; n \;<\; \frac{2^{h+1} - 1}{2 - 1} \;+\; 1\end{displaymath}

Simplifying a geometric series ( \(\sum_{k=0}^{n} x^k\) = \(\frac{x^{n+1} - 1}{x - 1})\)


\begin{displaymath}2^h \;\leq\; n \;<\; 2^{h+1}\end{displaymath}


\begin{displaymath}h \leq \lg n < h+1 \end{displaymath}

Since h is an integer, h = $\lfloor$ lg n $\rfloor$.


next up previous
Next: Up: Previous: