Skip to content

Latest commit

 

History

History
61 lines (42 loc) · 1.84 KB

6.1.md

File metadata and controls

61 lines (42 loc) · 1.84 KB

Exercises 6.1-1


What are the minimum and maximum numbers of elements in a heap of height h?

Answer

最多就是一颗很完美的二叉树,是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.

Exercises 6.1-2


Show that an n-element heap has height ⌞lg n⌟

Answer

所以h = ⌞lg n⌟

Exercises 6.1-3


Show that in any subtree of a max-heap, the root of the subtree contains the largest value occurring anywhere in that subtree.

Answer

这就是最大堆的性质.

This is the property of maximum heap.

Exercises 6.1-4


Where in a max-heap might the smallest element reside, assuming that all elements are distinct?

Answer

It must be in the leaf node.

Exercises 6.1-5


Is an array that is in sorted order a min-heap?

Answer

没有说明是递增数组还是递减数组,所以不一定.

We don't know whether it's an increasing order or descending order.

Exercises 6.1-6


Is the sequence [23, 17, 14, 6, 13, 10, 1, 5, 7, 12] a max-heap?

Answer

NO, because 7 > 6

Exercises 6.1-7


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.

Answer

挺容易推的,因为每增加两个节点,树的叶子节点就会往后推移一位.再注意一下取整的位置就行.

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.