Show that the running time of the build_heap function is $O(n)$
The main point is to do the analysis exactly without being sloppy. Let me define the depth of a node in this way. Depth of any leaf is 0 and depth of any non-leaf node is maximum depth among its children plus 1. One can note that
depth = $\log n - $ height.

Then for a particular node how much time does heapify take? By definition of depth you can see it is order of depth of the node.

Now the total time for buildheap is $$\sum_{d=0}^{\log n} \text{(number of nodes of depth d)}\cdot O(d).$$

Now my claim is that there are at most $n/2^d$ nodes at depth $d$ (can you see why?). For example number of leaves (depth 0) is at most $n/2^0 = n$. 

Then, building time is
$$ \sum_{d = 0}^{\log n}  \frac{n}{2^d} \cdot O(d) = O(n)\cdot\sum_{d = 0}^\infty  \frac{d}{2^d} = O(n) \cdot 2 = O(n). $$