What are the minimum and maximum numbers of elements in a heap of height h?
最多就是一颗很完美的二叉树,是2^(h+1) − 1 ; 最少的话最后一层只有一个,是2^h
What it is a perfect complete tree, it is 2^(h+1) - 1; when the last level has only one element, we have 2^h.
Show that an n-element heap has height ⌞lg n⌟
![](http://latex.codecogs.com/gif.latex? 2^{h+1}-1\geq x \geq 2^{h} \rightrightarrows \lg{x} \geq h \geq \lg(x+1)-1 )
所以h = ⌞lg n⌟
Show that in any subtree of a max-heap, the root of the subtree contains the largest value occurring anywhere in that subtree.
这就是最大堆的性质.
This is the property of maximum heap.
Where in a max-heap might the smallest element reside, assuming that all elements are distinct?
It must be in the leaf node.
Is an array that is in sorted order a min-heap?
没有说明是递增数组还是递减数组,所以不一定.
We don't know whether it's an increasing order or descending order.
Is the sequence [23, 17, 14, 6, 13, 10, 1, 5, 7, 12] a max-heap?
NO, because 7 > 6
Show that, with the array representation for storing an n-element heap, the leaves are the nodes indexed by ⌞n/2⌟ + 1, ⌞n/2⌟ + 2, ... , n.
挺容易推的,因为每增加两个节点,树的叶子节点就会往后推移一位.再注意一下取整的位置就行.
It is easy to conclude, every time we add two nodes, the index of leaf nodes will increase 1.
Follow @louis1992 on github to help finish this task.