the question:
what is the sum of heights of the vertices of a perfect binary tree (n vertices, the height of a leaf is 0)? explain shortly.
a. $\theta(logn) $ b. $\theta(nlogn) $ c. $\theta(n) $ d. $\theta(n^2) $
so, I know the answer is c, and I also saw a proof to this by searching in google. however, it was quite a long proof, and all I need is short explanation (that is a question from a test, and you have something like 5 minutes to answer it). I understood that there is a way of showing it by increasing and decreasing the sum of heights , but all I succeed in proving in this way is that the sum is O(nlogn).
how can you answer this shortly?
At height $1\leq i\leq \log n$, you have $2^{\log n -i -1} = 2^{-i}\frac{n}{2}$ vertices. Therefore, you want to compute $$ \sum_{i=0}^{\log n} i\cdot 2^{-i}\frac{n}{2} $$ It remains to show that $\sum_{i=0}^{\log n} i \cdot 2^{-i} = \Theta(1)$. The lower bound is easy, and the upper follows from $\sum_{i=0}^{\infty} i \cdot 2^{-i} = O(1)$.