1.A leftist heap with the null path length of the root being r must have at least 2 r + 1 − 1 2^{r+1}-1 2r+1−1 nodes
用递归:假如r成立,则对r+1,右路径r个点,则右子树有 2 r + 1 − 1 2^{r+1}-1 2r+1−1个点。
而左子树Npl至少也为r,则左子树的右路径至少r,则左子树至少 2 r + 1 − 1 2^{r+1}-1 2r+1−1, 2 ( 2 r + 1 − 1 ) + 1 = 2 r + 2 − 1 2(2^{r+1}-1)+1=2^{r+2}-1 2(2r+1−1)+1=2r+2−1
T
2.Merge the two leftist heaps in the following figure. Which one of the following statements is FALSE?
A.the null path length of 6 is the same as that of 2
B.1 is the root with 3 being its right child
C.Along the left most path from top down, we have 1, 2, 4, and 5
D.6 is the left child of 2
C
总是和右子树合并,
小的作为根,左子树照抄
沿着右侧上去检查Npl。Npl是孩子中Npl较小的那个+1
3 Delete the minimum number from the given leftist heap. Which one of the following statements is TRUE?
A.9 is NOT the root
B.24 is the left child of 18
C.18 is the right child of 11
D.13 is the left child of 12
D
4.With the same operations, the resulting skew heap is always more balanced than the leftist heap.
这个是不一定的
F
5.The right path of a skew heap can be arbitrarily long.
T
一直插入类似这种结构(第一个节点不是,是为了方便画)
这样,转过去以后,就会增长左边
左边转过来,就变成右边了
6.Which one of the following statements is FALSE about a skew heap?
A.Skew heaps do not need to maintain the null path length of any node
B.Comparing to leftist heaps, skew heaps are always more efficient in space
C.Skew heaps have O(logN) worst-case cost for merging
D.Skew heaps have O(logN) amortized cost per operation
B是对的,因为不需要存储Npl
C摊销是O(logN),最差应该大于logN
D是对的
7.The amortized time bound of insertions for a skew heap of size N is O(logN).
摊销是logN
T
8.The result of inserting keys 1 to 2^k−1 for any k>4 in order into an initially empty skew heap is always a full binary tree.
这个很神奇,但是测试一下发现是对的。
9.Merge the two leftist heaps in the following figure. Which one of the following statements is FALSE?
A.2 is the root with 11 being its right child
B.the depths of 9 and 12 are the same
C.21 is the deepest node with 11 being its parent
D.the null path length of 4 is less than that of 2
插入结果如图
D
10.We can perform BuildHeap for leftist heaps by considering each element as a one-node leftist heap, placing all these heaps on a queue, and performing the following step: Until only one heap is on the queue, dequeue two heaps, merge them, and enqueue the result. Which one of the following statements is FALSE?
A.in the k-th run, ⌈N/2^ k⌉ leftist heaps are formed, each contains 2^k
nodes
B.the worst case is when N=2^K for some integer K
C.the time complexity T(N)=O(N/2log2^0+N/2^2log2^1 +N/2^3log2^2+⋯+N/2^Klog2^(K−1)) for some integer K so that N=2^K
D.the worst case time complexity of this algorithm is Θ(NlogN)
对于D:分治,和归并差不多。T(N)=2T(N/2)+O(logN),复杂度为O(N)
其他没有问题。
11.Insert keys 1 to 15 in order into an initially empty skew heap. Which one of the following statements is FALSE?
A.the resulting tree is a complete binary tree
B.there are 6 leaf nodes
C.6 is the left child of 2
D.11 is the right child of 7
如果个数满足一个完全二叉树,那么用skew插入是可以插出完全二叉树的。1,2,4,8.叶子是8个(先别急着一个一个插入)
12.Merge the two skew heaps in the following figure. Which one of the following statements is FALSE?
A.15 is the right child of 8
B.14 is the right child of 6
C.1 is the root
D.9 is the right child of 3
A 应该是left child。插入结果如图, 1还得交换孩子,这个图有问题:
B14应该是left child, 原因是当插入到了一个NULL之后就返回了,不会交换孩子
13. If we merge two heaps represented by complete binary trees, the time complexity is Θ(N) provided that the size of each heap is N
Merge就是建新堆,复杂度是O(N) T
14.A skew heap is a heap data structure implemented as a binary tree. Skew heaps are advantageous because of their ability to merge more quickly than balanced binary heaps. The worst case time complexities for Merge, Insert, and DeleteMin are all O(N), while the amorited time complexities for Merge, Insert, and DeleteMin are all O(logN).
T,均摊复杂度为O(logN),最坏是O(N)
15.The NPL of each node in a heap is supposed to be calculated from top down.
应该从叶子开始算,F
16.Which one of the following may be a leftist heap?
AB
C
D
必须先是堆才行,也就是说大小顺序不能错,大的在上方,或者小的在上方,不能一会儿大一会儿小。
17.Merge the two given skew heaps. Which one of the following statements is FALSE?
A.3 is the root
B.17 is the right child of 16
C.39 is the right child of 25
D.25 is the left child of 14
C,插入结果如图
插入的时候注意:记录下右侧被插入的节点。只有这些节点需要交换孩子,例如6-14中,只有14的右侧被插入了,因此只有14的孩子需要交换。而6的孩子不需要交换。