Several highly voted answers have given excellent explanations. I will show several figures to show the proof clearly and hope it is easy to understand.
The height of heap h = O(log(N))
, where N
is the number of (internal) nodes.
Note: ◯ for internal nodes, and □ for external nodes or leaf nodes; values are only saved at internal nodes.